Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
compare variables
Based on Els’ txp tip here, I am trying to compare current year with posted year and return appropriate notices. It somehow doesn’t work and always returns posted year-current year
. Does anyone know why?
<txp:variable name="yr" value="<txp:php>echo date('Y');</txp:php>" />
<txp:if_variable name="yr" value='<txp:posted format="%Y" />'>
© <txp:posted format="%Y" />,
<txp:else />
© <txp:posted format="%Y" /> - <txp:php>echo date('Y');</txp:php>,
</txp:if_variable>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: compare variables
You need to use single quotes if you want the values be parsed. As you are using double quotes, the PHP block isn’t parsed. Change of the quotes and then that’s it. Textbook stuff.
Something like (untested, as always. I like risky life — they call me HotShot after all — no they don’t):
<!--
Set the variable named "year" to the current year
-->
<txp:variable name="year" value='<txp:php> echo safe_strftime("%Y"); </txp:php>' />
<!--
Compare the posting year to current year stored in
the variable named "year"
-->
<txp:if_variable name="year" value='<txp:posted format="%Y" />'>
© <txp:posted format="%Y" />,
<txp:else />
<!--
We can also use the variable to return the current year,
instead of using another block of PHP
-->
© <txp:posted format="%Y" /> - <txp:variable name="year" />,
</txp:if_variable>
Last edited by Gocom (2011-05-29 12:24:52)
Offline
Re: compare variables
You are my guru! I deleted the previous post as I realised that it wouldn’t work and made no sense. Is using <txp:php> echo safe_strftime("%Y"); </txp:php>
better than <txp:php>echo date('Y');</txp:php>
?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: compare variables
colak wrote:
better than
Both return current year +/- TZ — define better ;). Safe_strftime() is what posted tag uses, but is not necessarily better.
I deleted the previous post as I realised that it wouldn’t work and made no sense.
Heh, and I edited my previous post to remove my mention about that before seeing your reply, messy ain’t it. Clustertastic — yes, it’s real word (no, it’s not). I shall not stop confusing lurkers spectators.
Last edited by Gocom (2011-05-29 13:00:04)
Offline
Re: compare variables
Gocom wrote:
Heh, and I edited my previous post to remove my mention about that before seeing your reply, messy ain’t it. Clustertastic — yes, it’s real word (no, it’s not). I shall not stop confusing
lurkersspectators.
Chaos… Got to love it sometimes:)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Pages: 1