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

non-cached function within a foreach that passes values to f

 
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 -> Installation and Setup
View previous topic :: View next topic  
Author Message
nikotto
Smarty Rookie


Joined: 12 Jan 2004
Posts: 26

PostPosted: Tue Mar 02, 2004 6:44 pm    Post subject: non-cached function within a foreach that passes values to f Reply with quote

i have a kind of compicated problem, but i think this could be possible...

i want to have a uncached-function within a loop. could be done using a insert-function.
but - now i want to pass the value from the loop to the function!
should be possible using a register_function!

but this code doesn't work

my php code:
[php:1:7453a764f8]
if(!$smarty->is_cached("test.tpl")) {
$smarty->assign("foo", array(1,2,3,4,5,6,7,8,9,10));
}
$smarty->register_function("noCacheFunction", "noCacheFunction", false);

$smarty->display("test.tpl");

function noCacheFunction($param) {
return($param['i']." ".microtime());
}
[/php:1:7453a764f8]

test.tpl:
Code:

{foreach item=i from=$foo}
    {$i} -
    {noCacheFunction i=$i}<br><br>
{/foreach}


first time when no cache exists all works but then after a refresh i get this:
Fatal error: Smarty error: [in test.tpl line 3]: [plugin] unknown tag - 'noCacheFunction' (core.load_plugins.php, line 118) in [...]\Smarty.class.php on line 1883


could anybody tell me what am i doing wrong here?

thx
Back to top
View user's profile Send private message Send e-mail
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Mar 02, 2004 8:01 pm    Post subject: Reply with quote

is_cached() actually fetches the template. you have to register the noCache-function *before* you call is_cached().

on another note: it seems your want to register the 'i' attribute as cached:
$smarty->register_function("noCacheFunction", "noCacheFunction", false, array('i'));
this ensures $i retains the value it had when the cache was generated.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nikotto
Smarty Rookie


Joined: 12 Jan 2004
Posts: 26

PostPosted: Wed Mar 03, 2004 4:40 pm    Post subject: Reply with quote

much thx, works great!
reallly a very good feature!!

perhaps you could point out that you have to call the register_fucntion bevore the is_cached... for me it was not logical Very Happy

and the array('i') i missed - i thought it should not be cached - as it should always have a different value...

anyway, it works great now Very Happy

mfg
Back to top
View user's profile Send private message Send e-mail
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 -> Installation and Setup 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