Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[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
Re: [SOLVED] Variable value for current year?
Got it. Thanks, wet!
<txp:variable value='<txp:php>echo date("Y");</txp:php>' />
Offline
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
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
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>
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
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
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
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
Re: [SOLVED] Variable value for current year?
I would use the variable method if I was using the value in more than one place.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
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
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