Return to the weblog archive, return to the home page or learn more about the site

Migrating Textpattern Designs

Posted Sep 29, 2009 in Design and Web Design

Textpattern is a content management tool for blogs and small websites. It allows site designers to exercise a great deal of control over the layout and functionality of websites through a highly expressive template language modelled on XML markup tags.

One downside of TXP, however, is that the templates are all stored (along with page content and sometimes the CSS file) in the TXP database have to be constructed almost entirely inside TXP’s administration interface:

Now, editing code directly in browser textareas isn’t the worst thing in the world, but it’s not a lot better than, say, using Notepad on Windows. At least Notepad lets you use the tab key. And when you have to move a design from site to site, you have to recreate each template page and snippet (reusable snippets of template code are known as “forms” in TXP parlance) one by one.

However, I’m not here to critique TXP’s minor functional limitations. Instead I want to share a small but fairly advanced trick I discovered as I was trying to think of a way to move a fully working and complete design from a TXP install on my localhost up to the install on my production server. And it’s here that TXP’s database-centric template system becomes a significant advantage.

All TXP template pages are stored in a database table called “txp_page”. All TXP forms are stored in a database table called “txp_form”. So potentially, all you need to do to initiate an updated design on a TXP site is to over-write each of those tables in your production MySQL database with two exported tables from your local database.

Easier said than done, right?

Well, unless you’re really comfortable with command line MySQL, you’ll need, at minimum, a working version of PHPMyadmin on your server and some kind of database tool on your development machine. I use Sequel Pro, which makes finding and then exporting the requisite database tables as a “.sql” file very easy. Remember, you have to export each table separately for this to work.

As an aside, a real MySQL pro could probably tell me a much faster way to do what I’m describing. And I hope they do! But I’ve tried this method and it works a charm.

Important note: It should go without saying that you really have to back-up both your local and production database before you attempt this trick. I once lost several weeks worth of posts when I ran a database operation that I shouldn’t have. Though in my defence, it was a dodgy TXP database plugin that I was using AND I thought I was hitting the “run backup button”. Always double-check every action when you’re messing with databases.

So, once you’re in PHPMyadmin, select the first database table you need to update. Choose “import”, select the .SQL file on your local machine, then hit “go”. Once that’s merged into the database, choose the next table, import again, and, whammo-bammo. You’ve got a whole new Textpattern template live, without having to cut and paste into a single textarea. Pretty neat, huh?

4 comments so far

Comment by Alex at 27 January, 11:50 pm

Have you tried the plugin mcw_templates – it works really great. I use it for all my txp sites out there. Creating themes on my dev-system – exporting my theme (HTML files), FTPing the export to the real site and importing the theme. Switching the section settings and I’m done.

You can even export the default txp layout and start editing from scratch. That’s really comfortable!

Comment by Nick at 24 February, 03:10 am

Hi Alex,

Actually, I have used mcw_templates in the past but as it seems to be completely abandoned now, I just can’t justify to myself getting in too deep with it.

Comment by Alex at 28 February, 07:18 pm

Hi Nick,

the plugin might be abandoned but it still works very well – even with TXP 4.2.0. However, there is another plugin I found recently. It’s called hcq_templates – – it’s worth to look at it.

Comment by Mhunter at 12 May, 11:59 am

Thanks for this!! I’ve been an avid Textpattern user for years, and although I’ve tried all the other majors, I find Textpattern to be by far the easiest, most versatile platform that gives the highest level of control. With all my Textpattern sites I’m able to use pretty much straight CSS and HTML – no annoying and limiting template systems. I can’t recommend it enough, and I can’t wait to dig into these resources.

Commenting is closed for this article.