Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Set textpattern variable in php
I did a bit of digging and found the following:
global $variable
$variable['something']
After which one could access a txp variable named something with value something. My question is how do I use a different value to the name?
Offline
Re: Set textpattern variable in php
variable( array('name' => 'something', 'value' => 42) );
Offline
Re: Set textpattern variable in php
Thanks, wet. Tried your suggestions, but it throws a fatal error at me…
Fatal error: Function name must be a string in /textpattern/publish/taghandlers.php(3127) : eval()'d code on line 5
Any ideas?
Offline
Re: Set textpattern variable in php
What about:
global $variable;
$variable['something'] = "42";
I’m almost sure that one worked for me before.
Offline
Re: Set textpattern variable in php
@maniqui: Ah, misread. Yes, will also give that a try…
Found out that variable( array('name' => 'something', 'value' => 42) );
works, but it is actually a function and not a variable. I added on the $
, which then created the Fatal error.
Last edited by dl33 (2009-09-29 16:21:34)
Offline
Re: Set textpattern variable in php
variable(array('name' => 'min_wohnflaeche', 'value' => 90));
variable(array('name' => 'max_wohnflaeche', 'value' => 120));
OR
$variable['min_wohnflaeche'] = 90;
$variable['max_wohnflaeche'] = 120;
Running into a bit of trouble here. This sets the two txp variables just fine, but almost certainly as strings. Any way to make sure that they are set as integers?
Last edited by dl33 (2009-09-29 16:31:45)
Offline
Re: Set textpattern variable in php
dl33 wrote:
Found out that
variable( array('name' => 'something', 'value' => 42) );
works, but it is actually a function and not a variable. I added on the$
, which then created the Fatal error.
Ofcourse it is a function. All TXP tags are functions. If you want it to be in a string, then put it into string. This sets it (yes, it is a function):
variable(array('name' => 'something', 'value' => 42));
And this outputs it:
variable(array('name' => 'something'));
$variable['something'];
And we can also put the output results inside a string:
$mystring = variable(array('name' => 'something'));
$mystring = $variable['something'];
Running into a bit of trouble here. This sets the two txp variables just fine, but almost certainly as strings. Any way to make sure that they are set as integers?
Show us your code. Note that $variable
is a global. And (int)
, settype()
, etc. can be used to turn strings into integers and likewise.
Offline
Re: Set textpattern variable in php
Thanks a lot for the reply Gocom, but managed to solve the problem another way: This was for use with smd_query, so setting the db field as INT instead of making sure that the txp variable was an integer made the query go through… phpmyadmin to the rescue…
Offline
Pages: 1