|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
n0xor Smarty Rookie
Joined: 04 Dec 2014 Posts: 6
|
Posted: Thu Dec 04, 2014 9:17 pm Post subject: capture nocache block unexpected result |
|
|
I'm not quiet sure if this is a bug or I'm doing something wrong here but this is my code:
Code: |
{capture assign="c_content"}
{nocache}{$x = 17}{$x}{/nocache}
{/capture}
{json_encode($c_content)}
|
what I'm expecting is an json_encoded (well an escaped) string looking like this:
But instead I get this:
Code: | "\/*%%SmartyNocache:13949833015480cb4165a9c4-71441735%%*\/<?php $_smarty_tpl->tpl_vars['x'] = new Smarty_variable(17, true, 0);?>\/*\/%%SmartyNocache:13949833015480cb4165a9c4-71441735%%*\/\/*%%SmartyNocache:13949833015480cb4165a9c4-71441735%%*\/<?php echo $_smarty_tpl->tpl_vars['x']->value;?>\n\/*\/%%SmartyNocache:13949833015480cb4165a9c4-71441735%%*\/" |
Is that the way it's meant 2 be? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Dec 04, 2014 11:29 pm Post subject: |
|
|
It doesn't make any sense to capture no-cached content if the rest of the page is cached. Get rid of the no-cache tags, or try moving them to encapsulate the entire code snippit.
Code: | {nocache}
{capture assign="c_content"}
{$x = 17}{$x}
{/capture}
{json_encode($c_content)}
{/nocache} |
I don't know if I'd chalk that up as a bug, as in capture should play nicer with no-cache tags. But you wouldn't get what you want anyways. :/ |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Dec 05, 2014 1:20 am Post subject: |
|
|
It's not a bug. If captured content contains nocache code {capture} itself and ofcause all code which does use the captured results must be called in {nocache} sections. Everything else will not work. |
|
Back to top |
|
n0xor Smarty Rookie
Joined: 04 Dec 2014 Posts: 6
|
Posted: Fri Dec 05, 2014 9:31 am Post subject: |
|
|
mohrt wrote: | It doesn't make any sense to capture no-cached content if the rest of the page is cached. |
In the capture block there is of cause more code. Both together (nocached and cached code) should then be passed to the json_encode function
mohrt wrote: | Get rid of the no-cache tags, |
Not possible
mohrt wrote: | or try moving them to encapsulate the entire code snippet. |
That would mean to not cache the content of the page.
mohrt wrote: | I don't know if I'd chalk that up as a bug, as in capture should play nicer with no-cache tags. But you wouldn't get what you want anyways. |
I have already found a workaround (insert some unique id in the capture and replace it with the nocache content) but I think there should be a "better" or "intelligent" cache system which automatically makes those tags/blocks nocached if they deal with nocache data
E.g
Code: | {assign "a" "15" nocache}
{$b = a*3}
|
so due to the fact that $a is nocache $b becomes nocache too.
I think to a certain degree smarty already does this, but as reported for the {capture} this does not work
U.Tews wrote: | It's not a bug. If captured content contains nocache code {capture} itself and of cause all code which does use the captured results must be called in {nocache} sections. Everything else will not work. |
It indeed does work very well without the escape (json_encode).
Calling that function nocache gives undefined $c_content.
Having the {capture} nocached would result in require all those php variables and database connections and calculations of content just for a single variable. I do not see the efficient behind that.
Well of course it is ok if the capture block can not handle nocache data but I just can't imagine that printing pure php is the wanted and correct output, so I think this should be considered as being a bug, not saying that my expected output (in the example of my first post) would be the correct way.
But to both of you thanks for answering this so fast! |
|
Back to top |
|
|
|
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
|