4

I am using hook_views_pre_render() in order to calculate some values based on my $view->result and I can see how I can manipulate the arrays and I'm achieving some success with being able to drupal_set_message() my variables to the screen. However, I'm trying to actually alter the HTML output in the view - is this possible through the custom module?

I currently have a multi value field and in my Views table, I have a field for students which lists my students (nodes) in an unordered list - I'd actually like to only show the first student name and add "+ 8 more" (if there are 9 students altogether). While I can sort of drupal_set_message my variables - I'm unsure how you'd actually send this information to the view itself? Do you have to store the variables in the custom module and then send them to tpl.php files in Views?

I know this is possible using a pre made module but I'd rather know how it works myself. I'm just struggling to see how you output these things into the view itself using a custom module.

Here is an image:

enter image description here

Cheers, Garry.

3

hook_views_pre_render() gets the $view object passed by reference. This means that if you change the $view object inside your hook_views_pre_render() function, it doesn't need to be returned or saved or re-executed or anything. The view object itself, the same one that is rendered, is the one you're altering.

  • Looking at this again, I think that instead of hook_views_pre_render() I would create a custom field handler to do the transformation of the field. – beth May 13 '14 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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