
Smashing Magazine we smash you with the information that will make your life easier. really.
(X)HTML template systems in PHP
By Smashing Editorial, October 1st, 2006 in Developer's Toolbox | 19 Comments | Forum
Web developers find themselves sooner or later in a dire situation: their scripts become an entangled mess of code. Program logic, presentation logic and in a worst case scenario even layout and design are so interconnected with each other that the further development becomes difficult. Would one have thought ahead and had created a clear structure for the code - the so-called HTML-template-engines, the integrity of the layers would have been preserved.
A HTML-template-engine serves to separate program logic (PHP), from layout, (HTML) and design (CSS). Most existing template-Systems are not limited to HTML-models. They are generally usable for E-Mail and even XML.
Program code can be changed independently of the web site design. All this is theory though. In practice and complex projects this division can not be realized most of the time. To prevent inflating the program code unnecessarily with representation logic, another fourth level is often added. In this layer logical connections are processed, which directly affect the representation. Example: Table line paging or dynamic lists.
A further substantial advantage of HTML templates is the reusability of program code, design and layout. A template can be used in numerous places on a web site. Changes in a template affect all pages where this template is being used. This can save a considerable amount of time and money, because instead of several pages, just the template has to be changed and proofed. Links checked: May/26 2008.
Levels
Program logic
On this level typical script tasks are settled, for example retrieval and conversion of data from the data-base. If the HTML template system is initiated, variable html templates are assigned to the appropriate substitute symbols.
Layout-level
It consists of models, for example of HTML. The model of a specific site can be composed of several templates, which are joined in program logic more directly by the template system. The layout too will partly be determined on this level; for example a table. The design level is also a factor here, since style sheets can affect the layout.
Representation logic
Both levels for layout and representation-logic are often merged, so that representation logic is not completely separate from the layout. The representation logic is often found in HTML templates. It makes sense (representation logic for example also contains HTML), because it is in most cases easy and cost effective. It is not recommendable in principle and especially in complex projects though, because it diffuses the clear separation of levels. The representation logic should have therefore been paged out in separate template files.
Web developers have to make absolutely certain that they don’t write program logic into the level for representation logic. To do this is tempting, because it appears at first to be simpler then to conceptualize the clean separation of both levels. In the long run it pays off with low maintenance to put in the effort.
Design
The design is not directly interconnected with the logic or the template system. It - and partly the layout are essentially detached from all other logic layers and directed through a cascading style sheet.
Beyond that some Template systems offer extensions for form processing, because this area overlaps largely with the representation of Web contents. WYSIWYG programs such as Dreamweaver can be made compatible with template systems by simple extensions. (Author: Rene Schmidt)
Example
The following three files produce a HTML site, in which 20 words with randomly selected letters are shown. Even though this doesn’t make much sense, it demonstrates the function mode of a Template system quite good.
Program-logic (file: index.php):
The music plays within the script.
This simple example is an illustration
For the sake of simplicity, representation logic and layout are united here
Leave a Reply
Sponsors
- Advertise with us!
Smashing Links
Stay in touch
Popular Posts
- 100 Wordpress Themes
- 83 Wordpress Themes
- 80 AJAX Solutions
- 75 JavaScript Techniques
- 70 Best Photoshop Tutorials
- 70 Best Illustrator Tutorials
- 53 CSS Techniques
- 50 Blog Designs
- 50 Graffiti Artworks
- 50 Brilliant Photos
- 50 Movie Posters
- 40 Free Fonts
- 40 Creative Layouts
- 35 Beautiful Icon Sets
- Beautiful Desktop Wallpapers
- Beautiful Macro Photos
- Beautiful Underwater Photos
- Free Design Templates
- Free CSS Layouts
All Posts
- 35 Designers × 5 Questions
- 50 Designers × 6 Questions
- 404 Error Pages
- AJAX Libraries
- AJAX Solutions
- AJAX Tutorials
- Badges and Pins
- Batch Image Processing
- Black & White Photography
- Block Quotes
- Blog Designs 1, 2, 3, 4, 5
- Blog Headers
- Book Covers
- Brochures and Booklets
- Browsers Round-Up
- Browser Test Suites
- Buzz-Monitoring
- Calendar Designs
- Charts and Diagrams: Tools
- Cheat Sheets
- Code Beautifier
- Copyright Explained
- CSS Coding Techniques
- CSS Designs 1, 2, 3, 4, 5
- CSS Clean Code
- CSS Editors
- CSS Expert Ideas
- CSS Float Theory
- CSS Frameworks
- CSS Free Templates
- CSS Footers
- CSS Forms 1, 2
- CSS Frameworks
- CSS Galleries
- CSS Ideas
- CSS Layouts
- CSS Menus
- CSS Print-Layouts
- CSS Specificity
- CSS Styleguides
- CSS Tables
- CSS Tutorials
- CSS-Techniques
- CSS Tools
- Data Grids and Tables
- Data Visualization 1, 2
- Date Stamps
- Design Books 1, 2
- Design Magazines
- Designer's Checkpoints
- Divine Proportion
- Domain Tools
- Dreamweaver Tutorials
- Drupal
- E-Mail Delivery
- Favicons 1, 2, 3, 4, 5, 6
- Firefox Themes
- Fireworks Tutorials
- Flash Designs
- Flash Slideshows
- Flash Tutorials
- Fonts 1, 2, 3, 4, 5, 6
- Font Management
- Form Design Patterns
- Forums
- Fractals
- Gadgets 1, 2, 3
- Google AdSense
- Google PageRank
- Graffiti
- Graphics Design
- Grid-Based Design 1, 2
- Grunge Design 1, 2
- Hand-Drawing Style 1, 2
- Handwriting and Lettering
- Hotkeys
- HDR Pictures
- HTML Template Systems
- Icon Sets 1, 2, 3, 4, 5
- Icons, Templates 1, 2, 3
- Illustrator Tutorials 1, 2
- JavaScript Techniques
- jQuery
- Laptop Sleeves
- Laptop Designs
- Link Building
- Links in New Windows?
- Macro Photography
- Mascots
- Moleskine Art
- Motion Graphics
- Motion Blur Photos
- Movie Posters
- Music Videos
- Navigation Menus
- Newspaper Designs
- Online Converters
- Online Generators
- Packaging Design
- Pagination
- PDF Magazines
- Photoshop Actions
- Photoshop Tutorials 1, 2
- Pixel Art
- Podcasts
- PNG Transparency
- Portfolios
- Pricing Tables
- Product Designs
- Rain Photography
- RSS Best Design Practices
- RSS Feed Icons
- Screencasting
- Screensavers
- SEO Tools
- Shopping Carts
- Short Movies
- Slideshows & Lightboxes
- Smoke Photography
- Source Code Editors
- Splash Pages
- Start Pages
- Stock Icons
- Space, Nebula wallpapers
- Tab-Based Interfaces
- Tag Clouds
- Textures
- Textures & Backgrounds
- Texture Design
- Tooltips Scripts
- Tutorials
- Typefaces 1, 2
- Type Setting Principles
- Typographic Posters
- Typography In Motion
- Typography Showcase 1 2, 3
- Underwater Photography
- Usability Books
- Usability Glossary
- Usability Nightmares
- Usability Principles
- User Interfaces
- Version Control Systems
- Vintage & Retro Posters
- Vintage & Retro Designs
- Vintage & Retro Tutorials
- Wallpapers 1, 2, 3, 4
- Web 2.0 Tutorials
- Weblog Engines
- Whitespace & Simplicity
- Wordpress Plugins
- Wordpress Themes 1, 2, 3, 4
- Wordpress Toolbox
- WYSIWYG Editors
Fresh Bookmarks
22 Free Seamless Vector Pattern Resources Perfect For Web Design
A collection of resources and articles related to vector patterns.
10 New PHP Content Management Systems
All based on PHP.
25 Beautiful Logos with Sequential Concept
Sequential logos maybe is a new trend among logo designers.
Designing a blog with HTML5
Much of HTML 5’s feature set involves JavaScript APIs that make it easier to develop interactive web pages.
20+ CSS Data Visualization Techniques
Get inspired.
CSS3 – a big storm is coming
With CSS3 media queries and multi-column layouts it will be a whole new ballgame.
Woodgrain: A Free Social Media Icon Set
With 18 social networks represented alongside astandard RSS icon in PNG format,
Webdesign: Five Minute Upgrade
Making Your Design Pop.
45 Stylish Typographical Desktop Wallpapers
These beautifully designed wallpapers are not solely about typography.
The Light CMS Trend
A new trend in CMSs I’m calling “light” CMSs.
Blogroll
- Bittbox
- CatsWhoCode
- Colorburned
- Design Disease
- Designm.ag
- Deziner Folio
- Dr. Web Magazin (.de)
- Dr. Web Shop (.de)
- Freshome Blog
- FudgeGraphics
- I Love Typography
- MakeUseOf.com
- Naldzgraphics
- Noupe.com
- Pro Blog Design
- Search-This
- Six Revisions
- SmileyCat
- Spoon Graphics
- Typesites
- Usability Post
- Walyou
- Webdesigner Depot
- Weburbanist
- Wellmedicated








David (October 20th, 2006, 3:58 pm)
Smarty is a good template-engine and easy to use as well. But do we really need a template engine in PHP, when PHP is kind of a template engine itself? I think, the only real advantage auf engines like Smarty is caching. But that’s something you can have without performance killing rewrites of native php functions…
more: Link [www.nyphp.org]
there are even better solutions to separate logic and presentation. you don’t need more software, you just have do understand php. ;-)
Abdullah (November 1st, 2006, 9:37 pm)
Smarty is not a good template engine in my opinion. Template Power is easy as well as fast.
Tomislav Bilic (December 1st, 2006, 11:57 pm)
>you just have do understand php
Yes, but what in the case where you work in the team? You can hardly expect that 1 person will be the expert in PHP, XHTML, CSS, Javascript, XML, AJAX & everything else.
Using template systems gives you the possibility for specialization and team development.
pascal (March 5th, 2007, 6:39 pm)
I didn’t know that thank you, i will try this!
Ajay kumar singh (May 4th, 2007, 7:03 pm)
You can use “read a file content” in a php file and use str_replace for value substitution in a template
Jaxy
Ton (May 22nd, 2007, 7:41 am)
You might want to add TBS - TinyButStrong (http://www.tinybutstrong.com/). The philosophy is different and the results is what you would expect from a template system.
nanda (June 18th, 2007, 12:46 pm)
can you give some tips to make a templates please
Martin (July 20th, 2007, 9:16 pm)
Hi,
I didn’t know that thank you, i will try this!
juragan (August 2nd, 2007, 5:52 pm)
Hi,
Is that wordpress using smarty engine or what?
Thanks a lot.
igre (August 13th, 2007, 9:43 pm)
Does anybody know a similar way to implement templating system into Perl based web applications? I searched over the internet for Smarty for Perl but I guess that Smarty is PHP-only extension.
Syed Balkhi (August 29th, 2007, 2:17 pm)
i’ll definately have to agree with David in this case, as i believe Smarty is a good system and i think smashingmagazines should write a review about smarty also and explaining how to use it as some people still does not know.
It does gives another field for users to specialize in and that just helps. Even though wordpress is easy to design, but i believe smarty just breaks it down if the product is open source or such. But if for one man use i would prefer php if that person is good with php because with smarty you have to change the php files and than add more to smarty so its double the work, but does help in the end.
kL (May 22nd, 2008, 3:56 pm)
Link [phptal.sf.net] is missing from the list. It’s an implementation of Zope’s TAL (template attribute language) for PHP5.
yahooheaduni (August 15th, 2008, 3:03 am)
site look frog pets ugly stay green australia vacant
Hamed Hajizadeh (September 6th, 2008, 12:22 am)
Nice site very nice
Thanks for all post
Marko (October 1st, 2008, 3:16 am)
Looks nice :) I’ll try smarty for myself.
Alexwebmaster (March 3rd, 2009, 4:03 am)
Hello webmaster
I would like to share with you a link to your site
write me here Link []
Adams (March 3rd, 2009, 6:07 pm)
oh,I have met the same problem,thanks for your point,It gave me a good suggestion.
Encupsinsusia (March 30th, 2009, 8:00 pm)
Пля да тут через слово читать дабы смысл дошёл