View previous topic :: View next topic |
Author |
Message |
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Sun Jul 24, 2005 5:21 pm Post subject: extending assign with not-cacheable flag or {assigndynamic} |
|
|
Using the extended setup, I created my own object:
class Layout extends Smarty
In the admin section I created an Layout object, and I assigned a value
to admin_menu with TRUE In the user section, i created another Layout object and assigned the value of FALSE
I wrote a header in this way:
Code: |
{if $admin_section}
{include file="admin_menu.tpl"}
{else}
{include file="user_menu.tpl"}
{/if}
|
However, if $smarty->caching = true You will not have the expected results, because smarty seems to use a cached value of $admin_section
or to parse the (cached) value inside the template.
So I used this:
http://smarty.php.net/manual/en/caching.cacheable.php
and wrote:
Code: |
{dynamic}
{if $admin_section}
{include file="admin_menu.tpl"}
{else}
{include file="user_menu.tpl"}
{/if}
{/dynamic}
|
So I wonder if it would not be good to extend the assign function with a boolean flag, cacheable much the same as You have with functions :
$this->register_function(...,..., false); or to create a new tag like
{assigndynamic} tag. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Jul 24, 2005 7:35 pm Post subject: |
|
|
In this case, I think you are better off using a unique cache_id to differentiate from the two conditions. |
|
Back to top |
|
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Mon Jul 25, 2005 11:55 am Post subject: |
|
|
I presume You reference to:
http://smarty.php.net/manual/en/caching.multiple.caches.php
It can be a workaround to use multiple caches, maybe I can resolve it in this way, but only for static sections which may be cached. For dynamic sections (not cacheable sections) the problem returns and in this case, I can not use two caches, so I need to take attention to the conditional statement which use cached values !
My opinion, it's quite a pitfall if You use caching and You are using conditional statements to show content, those statements could be using caching values (not intended in this sample), but most often they need to re-validate the condition. So caching should be set off for those conditional inserts and this could be done by what I have proposed ?
Correct me if I am wrong. |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Jul 25, 2005 12:17 pm Post subject: |
|
|
Hi JurgenD,
what about using a custom function?
Code: | {menu isAdmin=$admin_section} |
So you can use
[php:1:18ff716fbe]$this->register_function(...,..., false);[/php:1:18ff716fbe]
to include the menu in a dynamic way.
Bye,
Markus |
|
Back to top |
|
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Mon Jul 25, 2005 2:08 pm Post subject: |
|
|
kills wrote: | Hi JurgenD,
what about using a custom function?
|
Yes, Markus, this is a shorter workaround for dynamic sections and I will use this to shorten the template code.
Currently my conclusion is still the same, You have to consider the cached values into account when You use logic. And this should be put clearly into the documentation or people will get wrong results, because the template engine makes a static parse, based on cached values. Or the template tags should be extended with some flags, as explained above.
Thanks for the workaround. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Jul 25, 2005 3:22 pm Post subject: |
|
|
I think I have a different view of the way the caching system should be viewed. Ideally, a cached image (ie. a static cache from a display/fetch request) will not have ANY dynamic content. Of course, there are situations where you would want to have dynamic sections but Smarty's design tends to put caching considerations into the control of the application rather than the template. In other words, it is the application that decides if a template needs multiple caches based on varying inputs rather than the template designer's choice of conditionals. There is a school of thought that the template designer is sometimes in the best position to make these determinations and it occurs to me that this is what you are getting at with your argumenet based on conditional sections. Perhaps you will like this thread: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1343 |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Jul 25, 2005 9:03 pm Post subject: |
|
|
JurgenD wrote: | My opinion, it's quite a pitfall if You use caching and You are using conditional statements to show content, those statements could be using caching values (not intended in this sample), but most often they need to re-validate the condition. So caching should be set off for those conditional inserts and this could be done by what I have proposed ? |
If you use caching, you don't redo conditionals on cached values. If you use caching you are caching the *output* of your display()-call.
To solve your problem/example above, I'd just turn off caching entirely from the controller when in admin-mode. |
|
Back to top |
|
|