I don't like to mix html/php/css code... but in some way WordPress forces me to do this bad thing. Is it possible, or is it a good idea to use something like Smarty or PHPTAL in WordPress themes/plugins?


Let's address possibility for starters.

There are two parts to front end output in WordPress:

  1. Theme template system, which is pretty flexible and relatively easy to adjust, although mostly PHP-centric
  2. Template tags (and related) functions, which are extremely PHP–centric and vary wildly as to how easy they are to adjust

So implementing templating engine in WP in general isn't just a possibility, it's a practical and real thing. WP solutions (of various quality and maintenance state) exist for most mainstream PHP-related templating engines.

But is it practical?

Same circumstances dictate that while it is relatively easy to start on templating engine implementation, it's very hard to finish at feature parity with WordPress core.

The typical approaches are:

  • bypass from template to WP functions transparently (giving up on some of template layer discipline and advantages)
  • step away from WP's APIs in favor of creating and using own original APIs/data structures in template layer

So as far as practicality goes — templating engine implementations excel at contained projects and use cases, such as web agencies using them for their clients.

For generic wide–market theme solutions WordPress is unfortunately too old and inflexible to be fully adapted to alternative templating options.

Plugins, as much more contained and varied units, can make use of templating much easier. They don't have to adhere to same conventions as themes and can just offer/enforce their own.


Of course it is possible: https://wordpress.org/plugins/smarty-for-wordpress/

If it is a good idea that depends on your skills. If you are more comfortable with smarty, then use it. I see no reason why not.

Not the answer you're looking for? Browse other questions tagged or ask your own question.