Splash of Style...Macs, Photography, Design, and other Passions

Using PHP With Textpattern

January 21, 2006 by debbie T | Textpattern

I am still in the experimental stage of Textpattern, but I have decided to try to use PHP includes instead of Textpattern form snippets. I like using my favorite code editor on my own hard drive, instead of coding online in Textpattern’s editor. This way I can upload any edits quickly with FTP instead of coping and pasting into the online editor.

Keep in mind, any php code must be enclosed in the <txp:php> ... </txp:php> tag set. No <?php> tags are needed to parse PHP. The special txp tag will parse the code for you.

I was having a little problem with PHP variables, and found an article over on the Textpattern FAQ


This translates to yes, you can use PHP variables, but you also have to also use the global keyword along with the variable, both where the variable is declared, along with any time it is called.

For example, to define a variable for your favorite color:

global $color;
$color = "pink";

To call this variable:

<txp:php> global $color; echo "Today, my favorite color is $color";</txp:php>

This will parse:

Today, my favorite color is pink.

I have my fingers crossed that I will be able to continue to use PHP includes instead of Textpattern forms.

Commments are closed for this article.