[PHPTAL] Cache options from PHP

B. Kamer post at bushbaby.nl
Mon Apr 7 14:31:45 CEST 2008


Thanks but,

this would mean that i still need to set caching properties within the  
template... I need to set caching options without a need for special  
markup...

setSource is a phptal method, so something like;

$instance = new PHPTal();

$templateSource = '<tal:block phptal:cache="3h">' .  
file_get_contents($tpl_file) . '</tal:block>';
$instance->setSource($templateSource);
$result = $instance->execute();

but it also seems a bit wierd.


On 7 apr 2008, at 13:40, Werner wrote:
> Hi!
>
> This should be fairly easy. You can set caching as a per-element  
> condition (if I understand your approach correctly) and cache it  
> accordingly by making use of  tal:condition.
>
> E.g, try something like this:
>
> ...in your code:
>
> $instance->cache_h3 = true;
>
> ...and in your template (note the use of "not" in the second block):
>
> <tal:block tal:condition="cache_h3" phptal:cache="3h">
>   ... caching h3 template stuff...
> <tal:block>
>
> <tal:block tal:condition="not:cache_h3" >
>   ... un-cached h3 template stuff...
> <tal:block>
>
> The only disadvantage to this approach is template markup  
> duplication (if content is not much different between the cached and  
> un-cached blocks).
>
> This is a quick-and-dirty way to get it done. Maybe someone has a  
> better idea?
>
> Kind Regards,
> Werner
>
> B. Kamer wrote:
>> Hi,
>>
>> just been introduced to phptal as an template engine and am  
>> investigating it...
>>
>> Would it be possible to set caching options not from within the  
>> template but rather from PHP? I need to be able to do this because  
>> the engine that utilizes the template engine decides the caching  
>> options?
>>
>> So instead of:
>>
>> <tal:block phptal:cache="3h">
>>    ... template ...
>> <tal:block>
>>
>> i need something like:
>>
>> $instance = new PHPTal();
>> $instance->setTemplate($tpl_file);
>> $instance->setCaching(''3h");
>>
>> $result = $instance->execute();
>>
>> thanks
>>
>> Bas
>>
>>
>> _______________________________________________
>> PHPTAL mailing list
>> PHPTAL at lists.motion-twin.com
>> http://lists.motion-twin.com/mailman/listinfo/phptal
>>
>
>
> _______________________________________________
> PHPTAL mailing list
> PHPTAL at lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>




More information about the PHPTAL mailing list