Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2024-08-15 15:49:48
- lindabb
- Member
- Registered: 2023-02-17
- Posts: 132
variable on the article
Hello,
I have article that has few variables like this
<txp:php>
$abcd=‘xx’;
</txp:php>
About 50 lines of HTML code in between, then
<txp:php>
echo $abcd;
</txp:php>
I get this error:
Tag error: <txp:php>
echo $abcd;
</txp:php> -> Warning: Undefined variable $abcd Issue detected while parsing form None on page testing_four
why article doesn’t recognize the variable on same page ? what I’m going wrong.
This one works, if within same php tag.
Tag error: <txp:php>
$abcd=‘xx’;
echo $abcd;
</txp:php>
Thank you
Offline
Re: variable on the article
Each <txp:php>
block is a separate entity. To make variables persist across them, you must register them as globals:
<txp:php>
global $abcd;
$abcd = 'xx';
</txp:php>
<!-- your code -->
<txp:php>
global $abcd;
echo $abcd;
</txp:php>
TXP Builders – finely-crafted code, design and txp
Offline
#3 2024-08-15 23:14:48
- lindabb
- Member
- Registered: 2023-02-17
- Posts: 132
Re: variable on the article
Thank you.
Offline
Pages: 1