Forums / Setup & design / Section missing through caching

Section missing through caching

Author Message

Jon Staines

Friday 08 December 2006 1:33:20 am

Hi everyone,

I've gone through every post related to caching and I still can't solve a problem I'm having in 3.6.10. I'm trying to show a block of text and an image as a copyright on certain pages. Whether to show it or not is decided by a check box in the classes which can have the copyright. It is only allowed to be shown in certain sections of the site (microsites under the main site). These sections have their own pagelayout template as an override. At the foot of this I had something like this:

{section show=$node.data_map.show_copyright.content}
Divs, images, text goes here
{/section}

This showed the image when the box was checked. But if you went to the page a second time, it disappeared. The node wasn't know the second time around. After a lot of forum searching and trial and error (the ttl 0 line at the top didn't fix it), I found that this stopped that problem:

{cache-block keys=array('copyright', $uri_string, $current_user.is_logged_in)}
{section show=$node.data_map.show_copyright.content}
Divs, images, text goes here
{/section}
{/cache-block}

Even though this had nothing to do with users being logged in it worked, both when users were logged in and not. I thought I had finally fixed it. But the next morning, the copyright was gone. More testing showed that it disappeared after the 2 hour cache default.

Can anyone help point out what I need to do/where I've gone wrong?

Regards
Jon Staines

André R.

Friday 08 December 2006 4:59:07 am

I kind of guess this is in the pagelayout or related templates -> You are not supposed to use $node in other templates then node templates. This is because the variable is only there (in pagelayout and included templates) when view caching is disabled or if the page you are viewing is not cached yet (no view cache for that node generated yet).

Edit: This is a long standing misunderstanding introduced at the time view cache was introduced to 3.x, this is fixed in 3.9 by removing the $node variable from pagelayout completely.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Jon Staines

Friday 08 December 2006 5:21:17 am

Thanks for the answer.

Would it be better to have something like this in the pagelayout:

{let $current_node=fetch(content,node,hash(node_id,$module_result.node_id))}
{section show=$current_node.data_map.show_copyright.content}

or

add some kind of section look up to some code in each of the node templates (article, folder, etc)?

Jon Staines

Tuesday 12 December 2006 1:22:51 am

The first option seems to have fixed the problem.