Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-05-29 11:58:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,257
Website GitHub Mastodon Twitter

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" />'>
&copy; <txp:posted format="%Y" />,
<txp:else />
&copy; <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

#2 2011-05-29 12:15:14

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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" />'>
	&copy; <txp:posted format="%Y" />,
<txp:else />
	<!--
		We can also use the variable to return the current year,
		instead of using another block of PHP
	-->
	&copy; <txp:posted format="%Y" /> - <txp:variable name="year" />,
</txp:if_variable>

Last edited by Gocom (2011-05-29 12:24:52)

Offline

#3 2011-05-29 12:22:56

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,257
Website GitHub Mastodon Twitter

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

#4 2011-05-29 12:37:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#5 2011-05-29 16:25:31

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,257
Website GitHub Mastodon Twitter

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 lurkers spectators.

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

Board footer

Powered by FluxBB