Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Conditionally evaluate one of a number of same tags
I have a shortcode that outputs two possible dates:
- A delivery date
- A countdown to that delivery date
So I can use it thus:
Order within <txp::delivery_date countdown /> to receive by <txp::delivery_date" />
All good. But when it gets close to the window – within a minute of it – I want to omit the above sentence entirely. Then, a minute later it’ll reset itself and show up again with the new delivery window. This is to avoid it saying silly things like “Order within 0 minutes to receive by Friday 25th”.
If I wrap it all in <txp:evaluate>
then it always shows, because the second tag always outputs something. I want to conditionally output the entire thing only if both contain something. If the first is empty, skip. I thought about using the evaluate
attribute around the first tag but that will only cover that one.
Doable?
Last edited by Bloke (2020-09-23 15:38:36)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Conditionally evaluate one of a number of same tags
You can try to pass a number to <txp:evaluate />
:
<txp:evaluate test="1">
Order within <txp::delivery_date countdown /> to receive by <txp::delivery_date" />
</txp:evaluate>
This should test the first tag only. Not sure whether it will consider 0
as empty (to test), but it should be easily tweakable if needed.
Offline
Re: Conditionally evaluate one of a number of same tags
Long shot alternative: would storing the first part – the countdown – as a variable work? Then use txp:evaluate
/ txp:if_variable
to test that for the second part, and insert the variable into the output string.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Conditionally evaluate one of a number of same tags
Both excellent suggestions. I expect the first one (test="1"
) will work but… the site’s currently running Txp 4.7.2 so it doesn’t do anything right now. Site needs an upgrade when I get a moment to test it out.
In the interim, I’ll go with the latter suggestion. Pre-compute the countdown and stash it in a variable and only display the whole string if it contains something.
Thank you both kindly. Just didn’t have my thinking head on.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline