Currently building a danish website with Textpattern, I ran into an issue with the date format. Even though I set the language to danish,
<txp:posted /> still uses english for weekdays and months. By googling around a bit, I’ve found this FAQ: How do I display time and date formats in my local language, which suggests that instead of
<txp:posted />, I’d use the following:
<txp:php> global $locale; setlocale(LC_ALL, 'nl_NL.UTF-8'); echo posted(array('format' => '%A %B %e %Y, %H:%M:%S')); setlocale(LC_ALL, $locale); </txp:php>
but doing that in all the article forms felt like a somewhat bad idea, at least for readability. Instead, I stripped out most of it and added the following line to the start of the page:
da_DK should be replaced with whatever language you wish to use. Another advantage, besides this being shorter, is that it lets you keep using the date format settings in TXP. And thus lets you keep using
<txp:posted /> in all its glory. Still, knowing a bit of strftime conversion specifiers won’t hurt you, it might come in handy sometime (impress your mom! set a date for a date! whatever!)
Header and footer include with <txp:output_form />
Another tip that really helps when building sites with many page templates (I guess most people using TXP does this already, so this is mostly for beginners) is to make “include files” for the header and footer, by using TXP forms. I use
www- as a prefix for site-related snippets so that they come last in the form listing, and thus every TXP page starts with:
<txp:output_form form="www-header" />
and ends with:
<txp:output_form form="www-footer" />
All in all, Textpattern is a lovely application. If it would just let me use my text editor instead of the browser for editing templates, we’d be best pals.
- Documentation on txp:posted
- PHP function reference of setlocale
- ISO Language codes â€“ I think they should be used in combination, much like
da_DK, that danish setting works fine for me anyway.
- New tag goodness from Jon Hicks, explaining many of the recent additions to TXPs template tags.
- how to embed PHP code in textpattern – this has changed a bit aswell since RC3
If you have any additions to good references, or know for a fact that what I’m doing with that setlocale() call in the header is plain stupid, please let me know. Thanks!