Re: [SMARTY-DEV] Here it is: Patch for {nocache} support
| From: | Wom.bat | Date: | Mon, 14 Apr 2003 17:26:18 +0000 |
| Subject: | Re: [SMARTY-DEV] Here it is: Patch for {nocache} support | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-1150@lists.php.net to get a copy of this message | ||
Wow... very cool... maybe this can be included into the next smarty release
:)
Regards,
David
----- Original Message -----
From: "André Rabold" <arabold@nero.com>
To: <smarty-dev@lists.php.net>
Sent: Monday, April 14, 2003 6:18 PM
Subject: [SMARTY-DEV] Here it is: Patch for {nocache} support
> Attention folks,
> the following patch is pre-pre-pre-beta ;-) But it should work well with
> Smarty 2.5.0.
>
> Here's what can be done with it:
>
> Imagine you have a cached template but want some parts to never get
cached.
> In this case you needed to use an insert tag {insert type="foo"}. I don't
> like this approach even if I know alot other people do ;-) It splits my
> templates too much because I use alot of user-specific buttons and links.
> After applying this patch the following is possible:
>
> {* This is a cached template *}
> This is cached: {$foo}
> {nocache}This is not cached: {$foo}{/nocache}
> This is cached again: {$bar}
>
> It work's pretty well for me even if it's not that fast anymore because I
am
> using an eval() call :-( Perhaps this can be fixed in a later version...
But
> hey, it's faster than not using any caching at all.
>
> For outputting the value of a single variable you can do
> {nocache}{$foo}{/nocache} or even {$foo|nocache} which prevents $foo from
> beeing cached too. You can even prevent a plugin function from beeing
> cached: {foo|nocache bar="blah"}
>
> Attention: You cannot use the nocache modifier with function parameters
yet.
> Things like {foo bar=$foo|nocache} won't work for now. I'll implement this
> asap.
>
> What I want to do now is to change the register_function to use an
> additional parameter "cached". This way you could do something like
> $smarty->register_function("foo", foo, false). That's because {nocache}
tags
> and modifiers gives too much possibilities to our designers. A designer
> shouldn't need to care if a specific function needs to be cached or not.
> It's better to let the developer decide, isn't it?
>
> ATTENTION AGAIN: The following patch is not testet in a productive
> environment. It works well for me but who knows if it works for you ;-)
>
>
> What do you think? Any ideas?
>
> Bye,
> André
>
>
>
> Index: Smarty.class.php
> ===================================================================
> RCS file: /repository/smarty/libs/Smarty.class.php,v
> retrieving revision 1.375
> diff -r1.375 Smarty.class.php
> 1107a1108
> > $_smarty_results =
> $this->_eval_cached_template($_smarty_results);
> 1176a1178
> > $_smarty_results =
> $this->_eval_cached_template($_smarty_results);
> 1890d1891
> <
> 1893c1894,1907
> <
> ---
> >
> > function _eval_cached_template($results) {
> > $cacheSmarty = new Smarty();
> > $cacheSmarty->left_delimiter = "<!--{#SMARTYCACHE#";
> > $cacheSmarty->right_delimiter = "}-->";
> > $cacheSmarty->caching = 0;
> > $cacheSmarty->_tpl_vars = $this->_tpl_vars;
> > $cacheSmarty->_compile_template("evaluated template", $results,
> $source);
> > ob_start();
> > eval('?>' . $source);
> > $results = ob_get_contents();
> > ob_end_clean();
> > return $results;
> > }
>
>
>
> Index: Smarty_Compiler.class.php
> ===================================================================
> RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
> retrieving revision 1.204
> diff -r1.204 Smarty_Compiler.class.php
> 388a389,391
> > if (($this->_within_nocache && $tag_command != "/nocache") ||
> ($this->caching &&
> in_array("nocache",explode("|",$tag_modifier)))) {
> > return "<!--{#SMARTYCACHE#".$template_tag."}-->";
> > }
> 488a492,501
> > case 'nocache':
> > if ($this->caching > 0)
> > $this->_within_nocache = true;
> > return "";
> >
> > case '/nocache':
> > if ($this->caching > 0)
> > $this->_within_nocache = false;
> > return "";
> >
> 1625a1639,1642
> > continue;
> > }
> > else if($_modifier_name == 'nocache') {
> > // skip nocache modifier
>
>
>
>
----------------------------------------------------------------------------
----
>
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>