Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#11 2018-10-12 15:56:32
- richtestani
- Plugin Author
- Registered: 2009-11-08
- Posts: 128
Re: Strainge problems with inline PHP not outputting TXT tags
etc wrote #314577:
Nope, it’s not parsed the first time. Inside
<txp:php>...</txp:php>
,'<txp:article_id />'
is just a string, nothing more. If you want it to be parsed, say it:
var_dump(parse('<txp:article_id />') == 5); //must return true...
So that helped, I was echoing my body from my own response, so instead I wrapped in parse.
echo parse($response->getBody());
So now within php tags:
<txp:php>
echo article_id([]); //outputs the proper id
</txp:php>
I still cannot use raw php tags with article_id, and get the out of context error. But I can get the ID. But, a new issue formed. Why cannot not access my own variables defined in the txp:php tags but I can with raw php tags?
<txp:php>
global $colors;
print_r($colors) //not defined
</txp:php>
then:
<?php
print_r($colors) //is defined
?>
how can I pull in $colors
which is available on the page otherwise?
Thank you
Rich
Last edited by richtestani (2018-10-12 16:01:46)
Offline
#12 2018-10-12 16:02:38
- etc
- Developer
- Registered: 2010-11-11
- Posts: 3,042
- Website
Re: Strainge problems with inline PHP not outputting TXT tags
I think raw php support was deprecated and removed in recent versions, you must use <txp:php />
. As for global variables, as soon as they are declared so in each block, it should work:
<txp:php>
global $colors;
$colors = ['blue', 'red'];
</txp:php>
...
<txp:php>
global $colors;
print_r($colors);
</txp:php>
Offline
#13 2018-10-12 17:13:32
- richtestani
- Plugin Author
- Registered: 2009-11-08
- Posts: 128
Re: Strainge problems with inline PHP not outputting TXT tags
etc wrote #314580:
I think raw php support was deprecated and removed in recent versions, you must use
<txp:php />
. As for global variables, as soon as they are declared so in each block, it should work:
<txp:php>...
I see.
So knowing some data comes from outside sources (imported classes and such)… how would you handle this? Build a public side plugin?
Offline
#14 2018-10-12 19:08:49
- richtestani
- Plugin Author
- Registered: 2009-11-08
- Posts: 128
Re: Strainge problems with inline PHP not outputting TXT tags
So after working out the plugin direction, it seems to work just as nicely.
<txp:rlt_colors article_id='<txp:article_id />' />
Fixes any issues I was dealing with prior, and moves my client code to a plugin.
Thank you for everyone’s input.
Rich
Offline