Using files for page templates in Textpattern
One of Textpattern’s drawbacks has always been that page templates are saved in the database. Editing them means using the textarea in the TXP admin interface, but I’m sure most people would prefer to use their favourite text editor.
Here’s a workaround that works in TXP 4.2.0 (I haven’t tried other versions).
- Enable ‘Allow PHP in pages?’ in Advanced Preferences if you haven’t already
- Set up your sections and corresponding page templates as you want them
- Copy and paste everything in your page template into a php file (such as ‘template.php’)
- Create a ‘pages’ folder in your textpattern directory and save the file there
- Replace the content of your page template in TXP admin with:
<txp:php>echo parse(file_get_contents(txpath.'/pages/template.php'));</txp:php>
From there on in, you can edit the php file. There may be a performance hit doing this, but all TXP tags work. Much easier!
7 Comments - Comments RSS Feed
Filipe Varela
# 10 July 2010
I followed their initial conversation on twitter and Sam Brown suggested this one:
<txp:php>include(txpath.’/pages/default.php’);</txp:php>
Jon updated his post, but now I see he has removed that one. Any idea why?
Joran Aerns
# 5 August 2010
Am I wrong when my first take on this is: modules could be treated as such?
Kilian Muster
# 6 August 2010
I so hoped that this would be a plugin-free easy solution, just to find out that it doesn’t work with the Multi-Language-Plugin (MLP).
If you use the MLP to localise text within templates via ##localised_text## tags, those will stop switching languages and are displayed straight as tags with the double hashes…. :-(

Marcus
# 9 July 2010
I’m using cnk_versioning for this purpose which is a way more elegant solution, imho.