Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2008-03-20 13:45:58
- feragnoli
- Member
- From: the hague
- Registered: 2005-02-10
- Posts: 150
Obtain variables from Txp tags..?
what’s the right way to implement tags/functions inside a php block?
for instance, how could I fetch the year of the last published article and then pass it into a variable?
if I would to something like:
<txp:php> $last_article_year = <txp:article form="year" limit="1" sort="Posted desc" /> </txp:php>
and inside the form just <txp:posted format="%y" />
I guess there’s a right way to just get that… in plain php..?
thank you
what was that again…?
Offline
Re: Obtain variables from Txp tags..?
Basically, all tag handlers are functions named just like the tag, which take an array of name=>value
tupels for the attributes and return their outcome. You might enjoy Textpattern Tags in Tags: The Gordian Knot, where I write about the tag handler interface from a related perspective.
As an alternate solution, you could delegate all the hard work to Textpattern’s own parser and settle back to something like this:
<txp:php> $last_article_year = parse('<txp:article form="year" limit="1" sort="Posted desc" />'); </txp:php>
Offline
#3 2008-03-20 14:45:29
- feragnoli
- Member
- From: the hague
- Registered: 2005-02-10
- Posts: 150
Re: Obtain variables from Txp tags..?
wet, thank you very much.
what was that again…?
Offline
Re: Obtain variables from Txp tags..?
If you’re already using the txp:php tag, then it’s a lot more efficient to call the tag function with an attribute array (and $thing) as parameters (as wet explains in his excellent gordian knot article), then calling parse() from within the txp:php tag.
Offline
#5 2008-03-20 18:03:56
- feragnoli
- Member
- From: the hague
- Registered: 2005-02-10
- Posts: 150
Re: Obtain variables from Txp tags..?
how can I pass what comes from parse('<txp:article form="year" limit="1" sort="Posted desc" />')
into an array?
the explode() functions seems not to agree with what comes in…
what was that again…?
Offline
#6 2008-03-20 18:17:46
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Obtain variables from Txp tags..?
<txp:php>
$last_article_year = article(array(
'form' => 'year',
'limit' => '1',
'sort' => 'Posted desc'
));
</txp:php>
Offline
#7 2008-03-20 20:11:26
- feragnoli
- Member
- From: the hague
- Registered: 2005-02-10
- Posts: 150
Re: Obtain variables from Txp tags..?
yes, that did it.
thank you very much.
may I ask why the output of this:
<txp:php>
$last_article_year = article(array(
'form' => 'year',
'limit' => '1',
'sort' => 'Posted desc'
));
</txp:php>
would differ from the one I get from this:
<txp:php> $last_article_year = parse('<txp:article form="year" limit="1" sort="Posted desc" />'); </txp:php>
?
what was that again…?
Offline
Re: Obtain variables from Txp tags..?
Those should give the same result… are you saying the result differs? And if so: what’s different?
Offline
#9 2008-03-20 20:36:38
- feragnoli
- Member
- From: the hague
- Registered: 2005-02-10
- Posts: 150
Re: Obtain variables from Txp tags..?
the result of the parsing is something like 09, 08, 07
.
when passing that to explode() I seem not to get a valid array, while if I pass what comes out of second I do.
Last edited by feragnoli (2008-03-20 20:37:16)
what was that again…?
Offline
Re: Obtain variables from Txp tags..?
Can you add echo var_dump($last_article_year);
in both situations and post which results that gives?
Offline
Pages: 1