1

How can I alter the results of a view with hook_views_post_render but save the altered output to cache, in order to avoid the overhead of altering the results on every request?

The ideal scanario should be like this: Is the cache expired -> Yes -> alter the view's output -> Save new output in cache, Otherwise don't alter the output.

  • Views caches query results and the rendered content. post_render happens after both those caches are queried, by definition. You could manually re-cache the results of the post render, of course, but, by design, next time the View is executed your post_render code will obviously be run again. I guess you could maintain state yourself to decide whether that post render should run once/twice/whatever, but it would make much more sense to move your logic into a pre_render hook – Clive Nov 20 '14 at 10:30
0

Yes Clive is right use

function hook_views_pre_render(&$view) {

instead of

function hook_views_post_execute(&$view) {

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.