Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'.

like image 279
anonymous coward Avatar asked Jun 03 '09 19:06

anonymous coward


People also ask

How implement inheritance in template file explain with Django?

To use Template Inheritance we must first create a base template. A base template is just a simple skeleton that we will be used as a base for all other pages on our site. A base template defines areas where content can be inserted into. In Django, we define this area using the block tag.

When Extend is used for inheriting a template?

extends tag is used for inheritance of templates in django. One needs to repeat the same code again and again. Using extends we can inherit templates as well as variables.

What template language does Django use?

Django Template Language or DTL is a text-based Template language that provides a bridge between scripts like HTML, CSS, JS, etc. and programming languages like python. DTL is specifically built for developers to embed Django logic codes into HTML template files.

What is PHP templating engines?

Ad. Ad. A PHP template engine is a concise syntax used by front-end developers to display data prepared by back-end developers.


1 Answers

Sorry to dig up an old thread, but I just released a library that does template inheritance in native PHP. Very inspired by Django. Please check it out and let me know what you think:

"PHP Template Inheritance"

http://arshaw.com/phpti/

like image 198
arshaw Avatar answered Nov 04 '22 04:11

arshaw