Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
assign to variable cached value

 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
wACKY
Smarty n00b


Joined: 12 Oct 2011
Posts: 1

PostPosted: Wed Oct 12, 2011 10:31 am    Post subject: assign to variable cached value Reply with quote

Hi

{assign var="key" value=$rec@key cached}

It will be easier to explain by example:

In foreach, when nocache section appear, possibility assign @KEY to a variable, but as cached/const. Value should be evaluated during cache creation and kept as const.

Something like this:
test.tpl:
Code:

{foreach $array as $rec}
  {if $rec.dynamic}
    {nocache}
      {assign var="key" value=$rec@key cached}
      {$array[$key].text}
    {/nocache} 
  {else}
    {$rec.text}
  {/if}
{/foreach}


So i'm able to pass single array with some "configuration" with selective caching.

test.php:
Code:

<?php
include_once 'libs/Smarty.class.php';
$smarty=new smarty();
$smarty->caching=1;
$smarty->assign('array',array(
            'r1'=>array('dynamic'=>true,'text'=>'dynamic'),
            'r2'=>array('dynamic'=>false,'text'=>'static')
          ));
$smarty->display('test.tpl');
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Oct 12, 2011 10:46 am    Post subject: Reply with quote

Corresponding question at Stack Overflow Need trick to use cached value in nocache section
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Fri Oct 14, 2011 1:42 am    Post subject: Reply with quote

This will be implemented in Smarty 3.2.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests 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