Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-27 18:10:35

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Assign global variable to the value attribute of txp variable tag

Is it possible to assign a php global variable as the value for the txp variable tag? Here’s how I’m trying to do it;

<txp:php> global $test_var; $test_var = “hello”; </txp:php>

<txp:variable name=‘currId’ value=’<txp:php> echo($GLOBALS[“test_var”]); <txp:php>’ />

the <txp:variable tag doesn’t hold the value. What am I doing wrong?

Offline

#2 2011-06-27 18:17:34

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Assign global variable to the value attribute of txp variable tag

The values of TXP’s variable tag are stored in $variable global as an array. You can assign variables using it, like so:

<!--
	Set a variable named "pet" with a value of "dog"
-->

<txp:php>
	global $variable;
	$variable['pet'] = 'dog';
</txp:php>

<!--
	And then an usage example.
	Let's test if our favorite pet is a dog:
-->

<txp:if_variable name="pet" value="dog">
	You like dogs, I know it.
<txp:else />
	Cats? You like cats? I do.
</txp:if_variable>

Offline

#3 2011-06-27 18:25:50

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Re: Assign global variable to the value attribute of txp variable tag

Thanks Gocom, you have saved me a lot of time.

Offline

#4 2011-06-27 18:26:33

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Assign global variable to the value attribute of txp variable tag

leafy_loader wrote:

Thanks Gocom, you have saved me a lot of time.

No problem, you’re very welcome :)

Offline

Board footer

Powered by FluxBB