Search code examples
phpmodel-view-controllertemplatestemplate-inheritance

How to implement Template Inheritance (like Django?) in PHP5


Is there an existing good example, or how should one approach creating a basic Template system (thinking MVC) that supports "Template Inheritance" in PHP5?

For an example of what I define as Template Inheritance, refer to the Django (a Python framework for web development) Templates documentation: http://docs.djangoproject.com/en/dev/topics/templates/#id1

I especially like the idea of PHP itself being the "template language", though it's not necessarily a requirement.

If listing existing solutions that implement "Template Inheritance", please try to form answers as individual systems, for the benefit of 'popular vote'.


Solution

  • The PHP language itself was designed for just these tasks, [unfortunately] it became capable of more and more over time and people who had started out with that simple syntax started implementing more and more complex tasks with that strangely evolved language.

    I think what you mean with template inheritance is best expressed as dynamic file inclusion in PHP, as simple as

    <? require $content ?>