problem with $view_parameters in cache

Author Message

Pierre SCALFATI

Sunday 04 October 2009 3:48:11 am

Hi all,

In my flat_left.tpl menu file I added the following in order to change css class depending on the href link I click on and which which link name is specified in my $view_parameters in URL.

Here's the code


		{def $current_year = currentdate()|l10n('shortdate')|extract(6,4)}
								
								{def $year_param = $module_result.view_parameters.year}
                                
                                
                                
								{if is_set($year_param)|not}
                                    {set $year_param = $current_year}
                                {/if}
                                
                                {def $current_node = fetch('content','node',hash('node_id', $module_result.content_info.node_id))}
                                
                                Archives                                 
                                {for $current_year to 2005 as $year}
                                	<a {if $year_param|eq($year)}class="selected"{/if} href="{concat($current_node.url, '/(year)/', $year)|ezurl(no)}">{$year}</a>
                                    {if $year|ne(2005)}-{/if}
                                {/for}

The aim of the above code is to check if there is a year specified as parameter in the URL. If there's a parameter specified in the URL, that means that the user has clicked on an archive Year and I must change the style of the link he clicked on to declare it as "selected', and this doesn't work.

This part of code if not working :

<a {if $year_param|eq($year)}class="selected"{/if} href="{concat($current_node.url, '/(year)/', $year)|ezurl(no)}">{$year}</a>
                                    {if $year|ne(2005)}-{/if}

The $year value stays on the first value loaded in cache and every time I click on a new value of year (or if I change it in the URL) it's alway this cached value which is selected... I tried to uncache the left menu using this

   {set-block scope=global variable=cache_ttl}0{/set-block}

... but it doesn't work.

A help would be appreciated as I spent a lot of time to try to find solution on ez.no without big success.

Many thanks to all of you.

Ivo Lukac

Sunday 04 October 2009 5:02:47 am

Left menu is not part of content so it is not cached with view cache. You need to look into pagelayout.tpl and flat_left.tpl to see which cache-block surrounds your code and add module_result.view_parameters.year into keys array of the cache block.

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

Pierre SCALFATI

Monday 05 October 2009 12:50:09 am

Many thanks Ivo, that's right and works correctly.

Cheers!!!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.