Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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
Offline