Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2012-10-11 08:14:18
- phuture303
- Member
- Registered: 2008-09-14
- Posts: 127
Using txp:variable in txp:php
Hey there,
my status quo: For my cinema website I define each wednesday evening the dates (as variables via adi_variables) for the new movie week (which starts in Germany on thursdays) and the following week.
thisweek: 11.10. – 17.10.2012
thisweek-thursday: 11.10.
thisweek-friday: 12.10.
thisweek-saturday: 13.10.
[…]
nextweek: 18.10. – 24.10.2012
nextweek-thursday: 18.10.
nextweek-friday: 19.10.
[…]
nextweek-wednesday: 24.10.
Well, doing this via adi_variables is very easy, but there must be a easier way because i don’ want to change 16 variables every week :-)
My idea:
- Defining the variable
weekstart
with value “2012-10-11” (this is something i’ll will renew every wednesday evening, that’s okay) - Calculating every other date-variable with php and date()
For thisweek-friday
this could be something like that:
<txp:php>$date = '<txp:variable name="weekstart" />';echo date('d.m.', strtotime('+1 days', strtotime($date)));</txp:php>
While <txp:php>$date = '2012-10-11';echo date('d.m.', strtotime('+1 days', strtotime($date)));</txp:php>
works without problems, the version above with txp:variable
doesn’t. Even inserting something like variable(array('name' => 'weekstart'))
instead of the txp-variable-tag won’t do it, but I think that the problem sits in front of the computer (no understanding of PHP with it’s variables and arrays at all :-)
Could anyone provide help? Would be great!
THX – David
Last edited by phuture303 (2012-10-11 08:15:20)
Offline
Re: Using txp:variable in txp:php
Hi,
declare global $variable;
and retrieve it as $variable['weekstart']
inside <txp:php />
.
Offline
Re: Using txp:variable in txp:php
Another suggestion: Do not use an undocumented global but the “official” tag handler function, conveniently named alike the corresponding tag:
<txp:php>
$weekstart = variable(array('name' => 'weekstart'));
</txp:php>
Offline
Re: Using txp:variable in txp:php
phuture303 wrote:
Even inserting something like
variable(array('name' => 'weekstart'))
instead of the txp-variable-tag won’t do it
Strangely that does not seem to work?
Offline
#5 2012-10-11 10:09:06
- phuture303
- Member
- Registered: 2008-09-14
- Posts: 127
Re: Using txp:variable in txp:php
Thanks guys,
now it works; it seems that I had some typos with '
in my variables!
In adi_variables
, it now looks like this:
start = 2012-10-11 // this variable I will change every wednesday evening manually
thisweek-thursday = <txp:php>$date = variable(array('name' => 'start'));echo date('d.m.');</txp:php>
thisweek-friday = <txp:php>$date = variable(array('name' => 'start'));echo date('d.m.', strtotime('+1 days', strtotime($date)));</txp:php>
[…]
nextweek-wednesday = <txp:php>$date = variable(array('name' => 'start'));echo date('d.m.', strtotime('+13 days', strtotime($date)));</txp:php>
Thanks a lot for your fast-as-lightning-help :-)
David
Last edited by phuture303 (2012-10-11 10:18:32)
Offline
Pages: 1