Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Counter

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
MC
Smarty n00b


Joined: 23 Sep 2012
Posts: 2

PostPosted: Sun Sep 23, 2012 4:27 pm    Post subject: Counter Reply with quote

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
Code:
 {counter}
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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4635
Location: Hamburg / Germany

PostPosted: Sun Sep 23, 2012 8:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
MC
Smarty n00b


Joined: 23 Sep 2012
Posts: 2

PostPosted: Sun Sep 23, 2012 9:30 pm    Post subject: Reply with quote

Yes you were right, that was the problem.

Thank you
Back to top
View user's profile Send private message
kiler6
Smarty n00b


Joined: 11 Oct 2013
Posts: 2

PostPosted: Fri Oct 11, 2013 9:11 pm    Post subject: Reply with quote

Thank you
templates for photoshop
underwear shop
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP