WebAppers

/ best free open source web resources /

Shopify

PHP Template Inheritance Makes Reusable HTML Layouts

Posted · Category: Framework, MIT License

Template Inheritance is an extremely useful technique for making reusable HTML layouts for a site. It is much more flexible than alternative techniques, such as “including” common elements of a page (like a header and footer file).

The concept has been around for a while, most notably in the Django template engine. Unlike other libraries, PHP Template Inheritance lets you write everything in straight PHP. There is no need to learn another template language.

It involves two separate templates, each in their own file: the parent template and the child template. The parent contains the HTML skeleton and markers for where content should go. These markers are calledblocks. The child then “fills-in” the blocks with content.

php-template

Requirements: PHP Framework
Demo: http://phpti.com/
License: MIT License

8 Comments
  • http://annanta.com Kevin S

    that is the reason i love web designing. We can do many more with html, css and php :) thanks for the awesome post :)

  • http://github.com/grimen grimen

    Heard of #content_for in Rails? ;D

  • http://n/a Nick

    Finally PHP re-invented the wheel or something all other use for ages – like masterpages ASP.NET. Good job guys!

    Now if you separate code from html/design to end this “spaghetti” madness… and eventually get rid of the $ in front of every variable it would be awesome. Unless you really want to see more dollars in your code.

  • Carlos

    @nick

    Lol, more dollars… PHP rules the web developer world!

  • http://www.karbon12.com Serge

    Nick: Smarty has separated code from design for a long time. Not only that, but Smarty has inheritance built into version 3.0.

  • http://wesam.ly Wesam Alalem

    thank you, another great stuff ;)
    I was thinking about using Smarty, but in my project is not that big. this is really handy.

  • Mike

    Yes, Smarty does separate code from design, but you do need to learn the template language. It is “too big” for a simple task. Nothing short of awesome, but way too bloated for small timers. I’m giving PHPTI a go.

  • http://arshaw.com/ Adam Shaw

    this project’s homepage has moved to http://arshaw.com/phpti/

Supported By

Deals

Web Browsers Icon Set
Food Icon Set
Flat Icon Set

Flat Icon Set

100 icons