smarty-php / smarty-php/smarty
default modifier ignores nocache on variables
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.3k
- Forks
- 709
- PR merge metrics
- No merged PRs in 30d
Description
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:
- Warn in the documentation you should not use default for variables that have nocache set
- Warn during the compile step if the default modifier is present (but not applied) for a variable which has nocache set
- Implement a nocache modifier or a default_nocache modifier
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests. Start by reproducing the interaction between the default modifier, nocache variables, template compilation, and caching. Done means a nocache variable receives its current value on later renders instead of a cached default, with regression coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100