|
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 |
amal Smarty Rookie
Joined: 30 Jul 2010 Posts: 5 Location: Samara, Russia
|
Posted: Fri Jul 30, 2010 9:54 am Post subject: Assigning a value to a variable from a template with nocahe |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Jul 30, 2010 3:31 pm Post subject: |
|
|
Yes, you can do it.
{$foo = ... nocache} |
|
Back to top |
|
amal Smarty Rookie
Joined: 30 Jul 2010 Posts: 5 Location: Samara, Russia
|
Posted: Sat Jul 31, 2010 4:58 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jul 31, 2010 1:38 pm Post subject: |
|
|
Indeed there was a bug. The fix is in the SVN now. |
|
Back to top |
|
amal Smarty Rookie
Joined: 30 Jul 2010 Posts: 5 Location: Samara, Russia
|
Posted: Sun Aug 01, 2010 7:43 pm Post subject: |
|
|
Thank you very much! |
|
Back to top |
|
alicia721 Smarty n00b
Joined: 07 Oct 2011 Posts: 1
|
Posted: Fri Oct 07, 2011 8:32 am Post subject: |
|
|
Wow, you've just solved my cialis online problem too. Cheers. |
|
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
|
|