Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2007-11-20 00:50:07
- alannie
- Member
- From: Minnesota, USA
- Registered: 2005-09-15
- Posts: 150
Trying to pass custom PHP variables
I’m trying to pass PHP variables from an URL string to an article in TXP. Here’s a simplified example of how I have it set up:
URL: http://mysite.com/section/article.php?custom=foo
Code in article body (with Article Markup set to “leave text untouched”):
<txp:php>
$custom = $_GET['custom'];
</txp:php>
<p><txp:php>echo $custom;</txp:php></p>
Everything in the page loads EXCEPT for the variable. Am I trying to do the impossible here? Or is my PHP just bad?
Offline
Re: Trying to pass custom PHP variables
err you should probably use this instead
http://textpattern.org/plugins/480/chsifurlvar
Offline
Re: Trying to pass custom PHP variables
Or use:
<txp:php>echo gps('custom');</txp:php>
Offline
#4 2007-11-20 13:58:04
- alannie
- Member
- From: Minnesota, USA
- Registered: 2005-09-15
- Posts: 150
Re: Trying to pass custom PHP variables
iblastoff wrote:
Works like a dream, thank you!! Now I have this:
URL:
http://mysite.com/section/article.php?custom=foo
Code in article body:
<p> <txp:chs_urlvar_echo var="custom" /> </p>
And it outputs:
<p> foo </p>
Thanks again, you saved me hours of work!
Offline
Re: Trying to pass custom PHP variables
Hmm. I was using GET for something on my website. I’m the only user… is it really bad If I use php?
THis is the code that I’ve been using and it works:
<txp:php> $id =($_GET['stockphoto']); echo '<txp:upm_image image_id=', $id, ' form="licensemeta" />'; </txp:php>
I tried to change this to
<txp:upm_image image_id="<txp:chs_urlvar_echo var="stockphoto" />" form="licensemeta" />
I also tried it without the double quotes and tried it with asy_wondertag, but it doesn’t work. Any thoughts.
Last edited by JonahC (2007-11-20 21:39:10)
Jonah Calinawan
www.foodportraits.com
Offline
Re: Trying to pass custom PHP variables
<txp:php>
echo upm_image(array('image_id'=>gps('stockphoto'), 'form'=>'licensemeta'));
</txp:php>
I tend to use PHP quite a lot, because I’m too lazy to write a plugin for such small things ;)
Last edited by ruud (2007-11-20 18:25:01)
Offline
Re: Trying to pass custom PHP variables
thanks ruud; i like the simplicity of your code, i’ll change mine. so from what you are saying using php is ok if it’s small enough. thanks.
Last edited by JonahC (2007-11-20 17:41:00)
Jonah Calinawan
www.foodportraits.com
Offline
Re: Trying to pass custom PHP variables
If you only needs such constructs every now and then, it’s a waste of time to turn it into a plugin. Plugins are mostly useful if they contain functions you use a lot. If you use them just once or twice, it’s probably quicker to use PHP code in your templates, because then the code only gets loaded when you really need it instead of each time you open a page.
PS. code updated, it contained an error.
Offline
Pages: 1