smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.22k stars 701 forks source link

default modifier ignores nocache on variables #1026

Open MichaONO opened 1 month ago

MichaONO commented 1 month ago

Hi,

I stumbled upon the following: I have a variable that is assigned in php with nocache set to true. But sometimes the variable does not get assigned at all. So I use the default modifier in the template for cases where the variable is not assigned. Caching is enabled.

Now when the template gets compiled while the variable is not assigned the compiler does not know about the nocache and thus probably caches the default value. When the page gets rendered again with the variable set (and nocache set to true), it still gets ignored. I suspect the reason is that the default value got cached during the compile step.

So I'd be happy if you could change this in a way that default values never get cached. The downside would be that also variables where the default is really cacheable would not get cached as well so I can understand why you would not want this. In that case I'd be happy if you could consider the following ideas:

Also I could just avoid using default for variables with nocache set or try using the nocache tag everywhere I use default. But that would not help anyone who stumples over the same thing and wonders what is going on.

Thanks Michael