I would like to get max amount of info on how the Wordpress implements the separation of presentation from code. I know that there is themes that one can load through the admin, but how does this get implemented programming-wise, and maybe also where it would be in the files.

I am learning the php and I want to figure out the best way of separating the presentation from code for a blog script (cms), tube script (videos and pic gals) and forum script. I will be writing these and I need to do the best possible separation of the above.

It seems like the options for now are: a) pick one of the already existing template renderers (like Twig, Blade; people say that Smarty is quite old, but this may be the most popular things still). b) make your own

I've heard about something like Moustasche a couple of times. It would be great if I could get some good WP and general info. I can work out the individual aspects but I am not sure what route should I choose. This would need to be the best thing that exists as the scripts are planned to be for sale.

I can add more info to this later on, as I will be doing the research (maybe Joomla, Drupal).

  • 1
    Hello @AndyRogers - Welcome to the WordPress Development community! Your question is very broad and largely a matter of opinion - as such it may be closed as it doesn't quite fit the direct Q&A format of our site. Please take a moment to review the "How to Ask" page in our help center, and then maybe file an edit if you think your question could be improved.
    – bosco
    Sep 4, 2018 at 18:34
  • The reality of this seems to be this - a) use Blade (the best way to go), b) use Twig (second best), c) use Smarty (someone told me that this is a little old, but from my own experience I know that this is a popular thing; the #1 tube script on the Net uses it), d) write your own (not the best option; this takes time to do and maintain), e) things like Moustache or other things like from gitHub are not the best option as this may be written for some specific use cases. So in the end it could be "write your own" as the best option but it takes effort and time. So Blade, Twig, Smarty, it seems Sep 5, 2018 at 6:03
  • You might want to take a look at Meadow - it's a Twig-based templating framework for WordPress written by a former WPSE moderator.
    – bosco
    Sep 5, 2018 at 14:14

1 Answer 1



Separate your view and business logic, or don't - WordPress doesn't care either way. Additional template engines aren't necessary.

Start small developing with vanilla PHP & WordPress; just build something that works, then separate it's view and business logic. Continue refactoring as you learn and the project grows. When you're comfortable with theme and plugin basics, consider migrating to a third-party template engine, and whether or not such a migration really contributes to the project's objectives.

Extension Structure

I would like to get max amount of info on how the Wordpress implements the separation of presentation from code.

How separation of view and business logic in WordPress itself is implemented varies considerably throughout the codebase, and is generally of little concern to theme/plugin developers. I won't delve into it here because it is a lengthy subject, and I don't believe it was your question's intent.

Themes and plugins alike have a single file-based entry point which WordPress executes at the appropriate time. Third-party code can then subscribe ("hook") to various events ("actions"/"filters") in order to interface with WordPress.

Outside of these restrictions the developer is offered complete control over their code structure and organization - there are some file-name-based conventions for automatically loading template files, but the developer needn't leverage this behavior. To separate view logic from business logic in a theme or plugin, you really just separate it. View and business logic have no inherent coupling in WordPress any more than in PHP itself. The line determining which code qualifies for which role is usually apparent in the WordPress APIs that the code leverages - views tend to only present data and make use of the WordPress "template tag" functions, while business logic is usually devoid of HTML and template tag calls.

Template Engine

One way or another, it's possible to use virtually any template engine with WordPress. But note that you neither have to select another template engine nor write one yourself. PHP by itself is more than adequate as a templating language. Consider that depending on the size and scope of your project, adding an additional template engine may unnecessarily complicate development and maintenance (and licensing, and update workflows, etc.).

Unless you have specific reasons for choosing a template engine here and now, I'd recommend familiarizing yourself with basic theme development using PHP and WordPress before deciding on a template engine such that you have a better frame of reference for selecting what you actually need rather than just adding popular code.

The Best Tool

This would need to be the best thing that exists as the scripts are planned to be for sale.

There is no one-size-fits-all solution for the "best" when it comes to software, which is why there is such an incredible variety of solutions out there. Here too, what design pattern you follow and what templating engine you use are entirely subjective - the only way to select the "best" option is to evaluate the needs of your project against the strengths and weaknesses of the available solutions. Even then you're likely to encounter opinion-based impasses which may require flipping a coin or simply following intuition.

If this is going to be a long-term or large-scale project, the time spent familiarizing yourself with each possible solution will be time well spent. Every developer has the experience of getting halfway through a project only to discover they chose the wrong tool for the job, and now must refactor significant chunks of their code-base or forge onward with ugly hacks and work-arounds. I'd recommend against choosing your technology stack based on ambiguous recommendations - what is "best" to some may very well be the worst thing for your project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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