Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#2 2024-08-15 17:18:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,699
Website

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

Board footer

Powered by FluxBB