I have a table of reservations which is built using Views module.

I want to highlight new reservations only 1 time. So I want to run a database update query (function db_update) after a page load. I tried to run it in hook_page_alter() or in hook_process(), but I didn't succeed, because query runs before showing a table. What hook should I use in my case?

  • You want to execute a query after page is actually displayed to an user? You know that the only way to do it is to use AJAX, right? If you have higher-level goal in mind, please share, maybe there is a simpler solution.
    – Mołot
    Dec 19 '13 at 12:25
  • To the editor - please use correct syntax. There are code ticks for code, don't use bold for that. And don't bold things in text when it isn't really really needed, you may shift accents to parts of the question OP did not meant as most important.
    – Mołot
    Dec 19 '13 at 12:35
  • 1
    Actually, for most uses answer by madhurjya should be enough and AJAX would be a bit of an overkill. My comments tells you how to get what you ask for, but probably not exactly what you really want ;)
    – Mołot
    Dec 19 '13 at 12:43

hope this will help

 * Post process any rendered data.
 * This can be valuable to be able to cache a view and still have some level of
 * dynamic output. In an ideal world, the actual output will include HTML
 * comment based tokens, and then the post process can replace those tokens.
 * Example usage. If it is known that the view is a node view and that the
 * primary field will be a nid, you can do something like this:
 * <!--post-FIELD-NID-->
 * And then in the post render, create an array with the text that should
 * go there:
 * strtr($output, array('<!--post-FIELD-1-->' => 'output for FIELD of nid 1');
 * All of the cached result data will be available in $view->result, as well,
 * so all ids used in the query should be discoverable.
 * This hook can be utilized by themes.
 * @param $view
 *   The view object about to be processed.
 * @param $output
 *   A flat string with the rendered output of the view.
 * @param $cache
 *   The cache settings.
hook_views_post_render(&$view, &$output, &$cache)
if ($view->name == 'your_view_name') 
   //do your logic
  • thank you for your answer, but it happens same as in hook_page_alter...
    – Saulius
    Dec 19 '13 at 12:31
  • In hook_views_post_render, the page is already constructed and in $output. You need to parse $output, and change it according to your logic.
    – Ursula
    Dec 19 '13 at 13:35

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.