Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

How do I edit a views field using preprocess before it is rendered to the screen? Let's say the field originally outputs something like this:

Note title

now I want to change that adding the number of comments in that node

Node title (4 comments, 1 new)

I know I can achieve this with joining two fields together or altering the template (tpl) files for that particular field but I'd like to learn how to use preprocess function in order to achieve this.

share|improve this question
add comment

2 Answers 2

There is help on Using default views in your module.

I also found this how-to helpful: Theming a view from within your module.

share|improve this answer
    
First link doesn't work. 2nd one is for Drupal 6 only. –  kenorb Jul 17 at 15:56
add comment

Drupal 7

Either you have to use hook_views_pre_render() or create appropriate TPL file (e.g. views-view-fields--MYVIEW.tpl.php) in your template dir (check Theme:Information in view edit page for more details).

You may also use preprocess theme function to print a single record from a row, with fields which is template_preprocess_views_view_fields().

Related:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.