I’ve been working on getting a better grasp on parse order, cached vs. uncached tokens, and all that good stuff. I thought I had it down, but I’ve managed to come up with a scenario that stumps me. Here’s the code:
[[setPoultry]] // sets placeholder 'chicken' to value 'poultry'
[[!setBird]] // sets placeholder 'chicken' to value 'a bird'
[[+chicken:notempty=`<p>A chicken is actually [[+chicken]]</p>`
:empty=`<p>where'd the chicken go?</p>`
]]
Parse order dictates that all cached tags are parsed first, from first-to-last, then all uncached tags are parsed, from first-to-last. So the tags are parsed in the order ’setPoultry’, ’+chicken’, ’!setBird’.
Since ’setPoultry’ comes before ’+chicken’ and sets a value for ’+chicken’, when ’+chicken’ gets parsed it finds a value. So the :notempty filter gets invoked, and the output for this code should be:
<p>A chicken is actually poultry</p>
With me so far?
That indeed is the output... the first time you view the resource (before it has been cached). But when you reload the resource, from then on the output becomes:
<p>where’d the chicken go?</p>
What this tells me is that after the resource has been cached... well, I’m not sure what it tells me. My theory goes something like this: even though +chicken is preceded in the code by an uncached resource that should set it to ’poultry’, its as if the resource cache knows that what is supposed to happen in the resource is that in the end, ’+chicken’ gets its value from the uncached snippet ’!setBird’. So it ignores the action of ’setPoultry’ and therefore somehow the ’:empty’ filter gets invoked (since the :empty/:notempty filters force the placeholder to be evaluated on the first pass-through rather than waiting for the uncached stuff to get parsed).
Is that a valid theory? If not, what the heck is going on here?
Just for kicks, when you change the placeholder to uncached:
[[setPoultry]] // sets placeholder 'chicken' to value 'poultry'
[[!setBird]] // sets placeholder 'chicken' to value 'a bird'
[[!+chicken:notempty=`<p>A chicken is actually [[+chicken]]</p>`
:empty=`<p>where'd the chicken go?</p>`
]]
Here the parsing order should be ’setPoultry’, ’!setBird’, ’!+chicken’. So I’d think that the output would be ’...a bird’ every time. But no... the first time you load the resource, you get ’<p>A chicken is actually poultry</p>’. And then after that you get ’<p>A chicken is actually a bird</p>’.
Can someone explain to me what is going on here?