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?


dawehner’s picture

there 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/

SomebodySysop’s picture

Thank you. This looks like it should do it. Just have to figure out how to modify the view footer.

dawehner’s picture

you could write a handbook or a blog entry if you managed to do it

by the way, you could also use hook_preprocess_...

merlinofchaos’s picture

In prerender you could:

  $view->display_handler->set_option('footer', $text);

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.

SomebodySysop’s picture

Status: Active » Fixed

Thank you! Haven't tried it yet, but I believe this is exactly what I was looking for.

SomebodySysop’s picture

Here's the code I used:

 * Implementation of hook_views_pre_render()
function views_mail_views_pre_render(&$view) {
  if (variable_get("views_mail_debug", 0) == 1) {
    drupal_set_message('pre_render tag : '. $view->tag); // DEBUG
    drupal_set_message('<pre>'. print_r($view, TRUE) .'</pre>'); // DEBUG
  // If set, display link on view
  if (variable_get('views_mail_view_link', 0) == 1) {
    if ($view->tag == 'views_mail') {
      $view->display_handler->set_option('footer', '<--My PHP CODE HERE-->');
      $view->display_handler->set_option('footer_format', '3');
      $view->display_handler->set_option('footer_empty', 0);

Works like a charm! Again, thanks for the help.

junedkazi’s picture

I 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gauravary’s picture

Version: 6.x-2.x-dev » 5.x-1.6
Status: Closed (fixed) » Needs review


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!


gauravary’s picture

Status: Needs review » Active
dawehner’s picture

Status: Active » Fixed

There is hook_views_pre_view(&$view, &$items);fi

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kenorb’s picture

jessehs’s picture

Note 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:

if ($view->name == 'my_view_machine_name' && $view->current_display == 'block_1') {
 ... custom code here...