Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I know that I can modify a view and enter php snippets into the header and/or footer fields.
What I would like to know is if there is some hook_views which would allow my module to insert a php snippet into a view footer on the fly?
Comments
Comment #1
dawehnerthere is the hook:
hook_views_pre_render (&$view)
i think you can use it to solve your problem
Found at http://views.doc.logrus.com/
Comment #2
SomebodySysop CreditAttribution: SomebodySysop commentedThank you. This looks like it should do it. Just have to figure out how to modify the view footer.
Comment #3
dawehneryou could write a handbook or a blog entry if you managed to do it
by the way, you could also use hook_preprocess_...
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedIn prerender you could:
Note that the text will be run through check_markup using 'footer_format', so you may have to change that as well. (You can get original text via get_option).
THis function will check default display too so you don't have to worry about overrides.
Comment #5
SomebodySysop CreditAttribution: SomebodySysop commentedThank you! Haven't tried it yet, but I believe this is exactly what I was looking for.
Comment #6
SomebodySysop CreditAttribution: SomebodySysop commentedHere's the code I used:
Works like a charm! Again, thanks for the help.
Comment #7
junedkazi CreditAttribution: junedkazi commentedI have also posted a write up of how to use the pre alter function for views.
The link is http://drupal.org/node/438370.
Pls do let me know if I have done anything wrong.
Comment #9
gauravary CreditAttribution: gauravary commentedHi,
I guess the hook "hook_views_pre_render()" only works for drupal 6. Is there any way to acomplish it for Drupal 5?
Thanks in advance!
Gaurav
Comment #10
gauravary CreditAttribution: gauravary commentedComment #11
dawehnerThere is hook_views_pre_view(&$view, &$items);fi
Comment #13
kenorb CreditAttribution: kenorb commented#6
Solution to: Views 3?
See: #749452: $view->display_handler->set_option('footer',$options) does not add footer in pre-render hook
Comment #14
jessehsNote that you can check to see which view and display you're modifying by the
$view->name
and$view->current_display
properties of the view object. Without wrapping your custom logic in a conditional statement, you'd be modifying every view. Ex: