Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

config_load and non-cached output don't mix?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
jdandrea
Smarty n00b


Joined: 06 Sep 2011
Posts: 4

PostPosted: Tue Apr 24, 2012 4:52 pm    Post subject: config_load and non-cached output don't mix? Reply with quote

Hello! Cross-posting from IRC.

I'm moving from 2.x to 3.x (latest version) ... and I notice that I'm no longer seeing config vars (that were loaded from a {dynamic} template block - see Example 15.14) within the scope of a Smarty function. Something like this:
Code:
{dynamic}
  {* Bits of logic determine which config/section to load. *}
  {config_load file=$configFile section=$sectionName}
{/dynamic}

I tried using {nocache} instead of {dynamic} as well, but that didn't help.

Note: Overall caching may or may not be set depending on the page being loaded. Usually it's set and then fine-tuned at the template or sub-template level.

I also notice that if I disable caching outright, the config vars always become visible! (When using the cache, clearing the full cache does not help either.)

I even tried adding scope="global" to the config load inside the template, but no luck.

About the only workaround I can seem to do is call configLoad from within the function ... but then there's all that logic in the template that I don't want to duplicate. I could move it to the function, but then the templates miss out on the loaded variables as well. Seems like it has to happen in the template first, then it's exposed to the function(s) that need it.

Meanwhile, if I switch back to v2, all's well. But I'd rather use v3! Smile

Clues/ideas welcome/appreciated!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Apr 25, 2012 10:10 am    Post subject: Reply with quote

Indeed it looks like that Smarty2 and Smarty3 have different behaviour of handling nocache sections.

In Smarty2 variable asignments or config variables loaded in nocache sections are also seen during rendering before the cache file is being written. In Smarty3 nocache sections are only executed in the context of the cache file.

I have to investigate how this can be solved.
Back to top
View user's profile Send private message
jdandrea
Smarty n00b


Joined: 06 Sep 2011
Posts: 4

PostPosted: Wed Apr 25, 2012 12:19 pm    Post subject: Reply with quote

U.Tews wrote:
In Smarty2 variable asignments or config variables loaded in nocache sections are also seen during rendering before the cache file is being written. In Smarty3 nocache sections are only executed in the context of the cache file.

Ahh! OK, whew, so I'm not totally insane. (Just a little bit <grin>.)

I appreciate any help in cracking the case - thanks!

Meanwhile, I need to think of a workaround. Let's see ... in Smarty3, nocache sections are executed "in the context of the cache" ... so here's a question:

Let's say I had a variable created at the time-of-rendering called FOO. Should that nocache section "see" that variable as it existed at the time of rendering? Perhaps not, as the variable could have changed several times over the course of rendering the template.

Worst case, perhaps I will need to factor out the variables that I need to have visible in the nocache section, and set those REGARDLESS, even if the template/id combo is already cached. OR ... if the variable in question can be tacked on to the template id, we don't need to worry about nocache at all. It just becomes a differently-cached version of the page. Hmm ... !
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Apr 25, 2012 2:08 pm    Post subject: Reply with quote

If you use variables within nocache sections these must be assigned/set also in case the page is in cache.

But this is true also for dynamic sections in Smarty2.
Back to top
View user's profile Send private message
jdandrea
Smarty n00b


Joined: 06 Sep 2011
Posts: 4

PostPosted: Wed Apr 25, 2012 4:24 pm    Post subject: Reply with quote

U.Tews wrote:
If you use variables within nocache sections these must be assigned/set also in case the page is in cache.

But this is true also for dynamic sections in Smarty2.

Got it. The variables to be used within a dynamic section all need to be set regardless of cache status, be it Smarty 2 or 3.

The config_load is still an issue. I think the only thing to be done for now is to load it outside of a nocache block, perhaps before any templates are invoked at all. That should be OK for now.
Back to top
View user's profile Send private message
jdandrea
Smarty n00b


Joined: 06 Sep 2011
Posts: 4

PostPosted: Wed Apr 25, 2012 9:38 pm    Post subject: Reply with quote

jdandrea wrote:
The config_load is still an issue. I think the only thing to be done for now is to load it outside of a nocache block, perhaps before any templates are invoked at all. That should be OK for now.

Arrrgh. That didn't help for anything that needs variables inside of a nocache block. Basically, there's a barrier that variables or configs simply can't cross. (I think this is what you were referring to in the first response.)

Bottom line - I have to ditch nocache usage.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP