On 02-11-2008 at 09:36:04 a b <[EMAIL PROTECTED]> wrote:

I'm very glad with using phptal:cache, especially with "per " parameter.
But now, I want to achieve something like that:

I have following template:

<div id="word" phptal:cache="1h per url">
            Word of the day is: <span tal:content="word">word of the
day</span>
</div>

Now I do:

{{
// :my php code: to retrieve word which takes very long to execute
// returns $word
$tpl=new PHPTAL('test.html');
$tpl->word = $word;
}}

I'd like to execute {{...}} only when cache is not fetched, else just
display cached HTML.

IMHO the best solution is:

$tpl=new PHPTAL('test.html');
$tpl->word = new WordGetter();

Word of the day is: <span tal:content="word/getWord"/>

Pass to the template an object that is cheap to create and have it do heavy work only on demand, e.g. when $word->getWord() is called. If the template is cached, the method won't be called.

An even simpler version of the same is:
<span tal:content="php:word_of_the_day()"/>

--
regards, Kornel

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to