Forums / Setup & design / Change header image in pagelayout depending on content

Change header image in pagelayout depending on content

Author Message

Nabil Imran

Wednesday 18 March 2009 4:11:42 am

Hi,

I want to make the header image at the top of the page change depending on the current node or path.

As the header image is part of the pagelayout, I added some code to pagelayout.tpl, that searches for alternative header images in the current path ($module_result.path). If an image is found under any node of the current path, it will be displayed at the top of the page. Otherwise a default image should be shown.

- When I delete the cache and reload the page, it works perfectly.
- When I reload the page several times after that, it works perfectly as well.
- BUT if I wait for some hours, and reload the page again, it always shows the default image!
- When I delete the cache again, it starts working for some hours again ...

What coult that be??

The code for this is located in the pagelayout.tpl, above the menu and the actual content. It is NOT in any cache-block.

I think this is NOT a problem in my code, but more a problem of pagelayout concept, or cache

<b>Any idea what might be the cause of this strange behaviour?</b>

Thank you for any help!!

Here is the code (just for helping you to understand, what I am trying):


                {* look for banner images somewhere in the current path *}
		{def $path_node_ids = array()}
		{foreach $module_result.path as $path_part}
			{set $path_node_ids = $path_node_ids|append($path_part.node_id)}
		{/foreach}
		{def $banner=fetch( 'content', 'list', hash( 'parent_node_id', $path_node_ids,
		                                              'sort_by', array( 'depth', false() ),
		                                              'class_filter_type', 'include',
		                                              'class_filter_array', array( 'banner' ),
		                                              'limit', 1 ) ) }
                {* if there is none, show default image *}
		{if not($banner[0])}
			{set $banner = fetch( 'content', 'list', hash( 'parent_node_id', ezini( 'NodeSettings', 'RootNode', 'content.ini' ),
		                                              'sort_by', array( 'depth', false() ),
		                                              'class_filter_type', 'include',
		                                              'class_filter_array', array( 'banner' ),
		                                              'limit', 1 ) ) }
		{/if}
                {* show the image*}
		{node_view_gui view='line' content_node=$banner[0] id='headerimage'}
		{undef $banner}