Project:Views
Version:5.x-1.6
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

#1

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/

#2

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

#3

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

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

#4

In prerender you could:

<?php
  $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.

#5

Status:active» fixed

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

#6

Here's the code I used:

<?php
/**
* 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.

#7

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.

#8

Status:fixed» closed (fixed)

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

#9

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

Hi,

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

#10

Status:needs review» active

#11

Status:active» fixed

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

#12

Status:fixed» closed (fixed)

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

#13

nobody click here