Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-10-18 11:18:01

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

[SOLVED] Variable value for current year?

I just deleted (accidentally) my variable tag that output the current year in my copyright statement, and now I can’t remember what it was. It was something like this, but I can’t seem to get it right: <txp:variable value="%y" />.

This should be in the Tag page as an example, and it will be once I remember what the dang value is. Anyone help?

Last edited by Destry (2012-10-18 11:38:10)

Offline

#2 2012-10-18 11:37:42

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [SOLVED] Variable value for current year?

Got it. Thanks, wet!

<txp:variable value='<txp:php>echo date("Y");</txp:php>' />

Offline

#3 2012-10-18 11:49:13

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [SOLVED] Variable value for current year?

Okay. Got it. In fact I didn’t delete my variable, I was using value when I should have been calling my variable by name, <txp:variable name="current_year" />

The variable I had was <txp:variable name="current_year"><txp:php>echo safe_strftime('%Y');</txp:php></txp:variable>

I think wet’s version would work too if I changed the source to what he provided. Is one more recommended than the other?

Last edited by Destry (2012-10-18 11:50:24)

Offline

#4 2012-10-18 15:45:31

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Variable value for current year?

none of these examples output the year for me.

error
Tag error: <txp:variable value='<txp:php>echo date("Y");</txp:php>' /> -> Textpattern Notice: variable_name_empty while parsing form None on page default

Last edited by bici (2012-10-18 15:47:09)


…. texted postive

Offline

#5 2012-10-18 16:04:57

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: [SOLVED] Variable value for current year?

You must name your variable.

<txp:variable name="mydate" value='<txp:php>echo date("Y");</txp:php>' />

If all you want is to print the year then just use

<txp:php>echo date("Y");</txp:php>

or

<txp:php>echo safe_strftime('%Y');</txp:php>

My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#6 2012-10-18 16:07:12

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [SOLVED] Variable value for current year?

Bici,

Create a form in miscellaneous (e.g., “variables”) and put this in it…

<txp:variable name="current_year"><txp:php>echo safe_strftime('%Y');</txp:php></txp:variable>

(Or you could use the single tag version of wet’s above.)

Then in the very top (where I have mine) of your page template—either directly or via another form—add this line…

<txp:output_form form="variables" />

Lastly, down in your copyright statement add this where you want to see “2012”…

<txp:variable name="current_year" />

Ed. Matt beat me to it.

Last edited by Destry (2012-10-18 16:10:14)

Offline

#7 2012-10-18 16:15:56

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Variable value for current year?

thanks Destry and MattD: Working now… both versions. ;-)

Hard to get my head around that it doesn’t work by simply asking it to via the code that Wet and Destry had. Counter intuitive that it’s a three-step process. BUT it is what it is.
l
Still learning….


…. texted postive

Offline

#8 2012-10-18 16:18:18

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

Re: [SOLVED] Variable value for current year?

So guys,

What is the advantage of using the variable instead of just going for <txp:php>echo safe_strftime('%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

#9 2012-10-18 16:53:19

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: [SOLVED] Variable value for current year?

I would use the variable method if I was using the value in more than one place.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#10 2012-10-18 16:55:33

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [SOLVED] Variable value for current year?

What Matt said. Also, you can put more than one variable in the “variables” form, and call them all to the top of the page templates at once, then call the different variables throughout the templates, as needed. That’s where the 3-way process really starts having power.

Offline

#11 2012-10-23 15:35:55

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: [SOLVED] Variable value for current year?

You might love to use adi_variables

Offline

#12 2012-10-23 16:31:53

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,120
Website Mastodon

Re: [SOLVED] Variable value for current year?

phuture303 wrote:

You might love to use adi_variables

one could put this string <txp:php>echo safe_strftime('%Y');</txp:php> into an adi field?


…. texted postive

Offline

Board footer

Powered by FluxBB