Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assigning a value to a variable from a template with nocahe

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
amal
Smarty Rookie


Joined: 30 Jul 2010
Posts: 5
Location: Samara, Russia

PostPosted: Fri Jul 30, 2010 9:54 am    Post subject: Assigning a value to a variable from a template with nocahe Reply with quote

Can I assign it a value within the template with nocache flag?
The output from the var flag with nocache not fit - in the cache of template this variable is not even created.

Code example:
Code:

   {* Tabs *}
   {$tabs = [
      ['friends', "{$WEB_URL}/my-news/friends"],
      ['groups', $js],
      ['comments', "{$WEB_URL}/my-news"],
      ['forum', {$WEB_URL}/my-news/forum"]
   ]}

   <div class="i-tabs">
      {foreach $tabs as $t}
         <a href="{$t[1]}" class="tabItem {if $t[0] == $type} active{/if}">{$t[0]}</a>
      {/foreach}
   </div>



I need something like {$tabs = [] nocache}
Is this possible?
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Fri Jul 30, 2010 3:31 pm    Post subject: Reply with quote

Yes, you can do it.

{$foo = ... nocache}
Back to top
View user's profile Send private message
amal
Smarty Rookie


Joined: 30 Jul 2010
Posts: 5
Location: Samara, Russia

PostPosted: Sat Jul 31, 2010 4:58 am    Post subject: Reply with quote

I wrote in template:

Code:

   {* Табы *}
   {$tabs = [
      ['friends',      'Новости друзей',      "{$WEB_URL}/my-news/friends"],
      ['groups',      'Обновления в группах',   $js],
      ['comments',   'Комментарии',         "{$WEB_URL}/my-news"],
      ['forum',      'Форум',            "{$WEB_URL}/my-news/forum"]
   ] nocache}

   <div class="i-tabs">
      {foreach $tabs as $t}
         <a href="{$t[2]}" class="tabItem {if $t[0] == $type} active{/if}">{$t[1]}</a>
      {/foreach}
   </div>


But it does not work!
In a cached code, there is no foreache cycle.
But if you assign a variable as not cached from outside php then the cycle will be in the cached code.


Compiled code:
Code:

      <?php $_smarty_tpl->tpl_vars['tabs'] = new Smarty_variable(array(array('friends','Новости друзей',($_smarty_tpl->getVariable('WEB_URL')->value)."/my-news/friends"),array('groups','Обновления в группах',$_smarty_tpl->getVariable('js')->value),array('comments','Комментарии',($_smarty_tpl->getVariable('WEB_URL')->value)."/my-news"),array('forum','Форум',($_smarty_tpl->getVariable('WEB_URL')->value)."/my-news/forum")), true, null);?>

   <div class="i-tabs">
      <?php  $_smarty_tpl->tpl_vars['t'] = new Smarty_Variable;
 $_from = $_smarty_tpl->getVariable('tabs')->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
if (count($_from) > 0){
    foreach ($_from as $_smarty_tpl->tpl_vars['t']->key => $_smarty_tpl->tpl_vars['t']->value){
?>
         <a href="<?php echo $_smarty_tpl->tpl_vars['t']->value[2];?>
" class="tabItem <?php echo '/*%%SmartyNocache:64024c53b02019be46-93746521%%*/<?php if ($_smarty_tpl->tpl_vars[\'t\']->value[0]==$_smarty_tpl->getVariable(\'type\')->value){?>/*/%%SmartyNocache:64024c53b02019be46-93746521%%*/';?> active<?php echo '/*%%SmartyNocache:64024c53b02019be46-93746521%%*/<?php }?>/*/%%SmartyNocache:64024c53b02019be46-93746521%%*/';?>"><?php echo $_smarty_tpl->tpl_vars['t']->value[1];?>
</a>
      <?php }} ?>
   </div>



Cached code:
Code:

   <div class="i-tabs">
               <a href="http://3run.ru/my-news/friends" class="tabItem <?php if ($_smarty_tpl->tpl_vars['t']->value[0]==$_smarty_tpl->getVariable('type')->value){?> active<?php }?>">Новости друзей</a>
               <a href="javascript:;" class="tabItem <?php if ($_smarty_tpl->tpl_vars['t']->value[0]==$_smarty_tpl->getVariable('type')->value){?> active<?php }?>">Обновления в группах</a>
               <a href="http://3run.ru/my-news" class="tabItem <?php if ($_smarty_tpl->tpl_vars['t']->value[0]==$_smarty_tpl->getVariable('type')->value){?> active<?php }?>">Комментарии</a>
               <a href="http://3run.ru/my-news/forum" class="tabItem <?php if ($_smarty_tpl->tpl_vars['t']->value[0]==$_smarty_tpl->getVariable('type')->value){?> active<?php }?>">Форум</a>
         </div>



Can you help me with this problem?
Smarty 3.0 RC3
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Sat Jul 31, 2010 1:38 pm    Post subject: Reply with quote

Indeed there was a bug. The fix is in the SVN now.
Back to top
View user's profile Send private message
amal
Smarty Rookie


Joined: 30 Jul 2010
Posts: 5
Location: Samara, Russia

PostPosted: Sun Aug 01, 2010 7:43 pm    Post subject: Reply with quote

Thank you very much! Smile
Back to top
View user's profile Send private message Visit poster's website
alicia721
Smarty n00b


Joined: 07 Oct 2011
Posts: 1

PostPosted: Fri Oct 07, 2011 8:32 am    Post subject: Reply with quote

Wow, you've just solved my cialis online problem too. Cheers. Wink
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 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