|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
MC Smarty n00b
Joined: 23 Sep 2012 Posts: 2
|
Posted: Sun Sep 23, 2012 4:27 pm Post subject: Counter |
|
|
Problem with counter in version 3.1.11.
I am using this code:
Code: |
{counter start=0 skip=1 direction=up print=false assign=i}
{foreach from=$Menus item=one}
{if $i is div by 2}
</div>
<div class="topSubmenuLinksBox">
{/if}
{if $currentParent == $one.ID}
<a href="{$one.more}" title="{$one.title}" class="current">{$one.title}</a>
{else}
<a href="{$one.more}" title="{$one.title}">{$one.title}</a>
{/if}
{counter}
{/foreach}
|
When I clean my cache every thing is working ok, counter is not printed out and Code: | {if $i is div by 2} | is working correct .
But when cache is created and I refresh page, counter is always printed out and Code: | {if $i is div by 2} | is not working correctly.[/code]
If I delete counter is not printed out any more, but also code is not working.
I think that flag print is not working correct.
This is error log:
Code: |
PHP Notice: Undefined index: i in /mod_shopCatMenu/cache/_497359900800^a62c3440193f83eb5972ad26d66e52486fedf474.view_default.tpl.php on line 34
PHP Notice: Trying to get property of non-object in /mod_shopCatMenu/cache/_497359900800^a62c3440193f83eb5972ad26d66e52486fedf474.view_default.tpl.php on line 34
|
Line 34 in cache:
Code: | <?php if (!($_smarty_tpl->tpl_vars['i']->value % 2)){?> |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Sep 23, 2012 8:55 pm Post subject: |
|
|
It looks like that you did assign $Menus as nocache variable like
$smarty->assign('Menus',array(...),true);
As result the {foreach} loop will be executed in nocache mode, but the initial
{counter start=0 skip=1 direction=up print=false assign=i}
is not.
If $Menus must be nocache force the initial {counter...} call to be executed also in nocache mode
Code: | {nocache}
{counter start=0 skip=1 direction=up print=false assign=i}
{foreach from=$Menus item=one}
{if $i is div by 2}
</div>
<div class="topSubmenuLinksBox">
{/if}
{if $currentParent == $one.ID}
<a href="{$one.more}" title="{$one.title}" class="current">{$one.title}</a>
{else}
<a href="{$one.more}" title="{$one.title}">{$one.title}</a>
{/if}
{counter}
{/foreach}
{/nocache} |
or if the whole thing can be cached assign $Menus normal
$smarty->assign('Menus',array(...)); |
|
Back to top |
|
MC Smarty n00b
Joined: 23 Sep 2012 Posts: 2
|
Posted: Sun Sep 23, 2012 9:30 pm Post subject: |
|
|
Yes you were right, that was the problem.
Thank you |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|