Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good templating system for PHP? [closed]

Tags:

php

templates

What's the best/easiest to integrate templating system for PHP, and what are the benefits of using one?

I currently don't use one at all, and am thinking that it might help to seperate content from presentation a little more.

like image 315
Rich Bradshaw Avatar asked Oct 13 '08 12:10

Rich Bradshaw


People also ask

Is PHP a templating language?

PHP is not a template engine, but a language that can be used to write templates, or template engines. A template engine is not just a language, but also the programming API that allows the scripts to locate, organize templates or assign the data from the script to them.

What is a PHP template engine?

A PHP template engine is a way of outputting PHP in your HTML without using PHP syntax or PHP tags. It's supposed to be used by having a PHP class that will send your HTML the variables you want to display, and the HTML simply displays this data.

Which of the following is a PHP based template *?

2. Smarty. Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Why is laravel template engine fast?

Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes. All views in Laravel are usually built in the blade template. Blade engine is fast in rendering views because it caches the view until they are modified.


3 Answers

PHP is a pretty good templating language by itself. Most leading PHP frameworks don't use a seperate templating langauge for just this reason.

Just make sure you use (something resemebling) MVC, and don't do any data access or business logic inside your view files.

I've also used Smarty extensively, but find it has little advantage compared to straight PHP, except for forcing you to keep your view dumb. It might also looks a little better to designers, but the down side is flexibility to you, the template implementor. Things like looping over triply-nested arrays become harder than with straight PHP.

like image 107
Alexander Malfait Avatar answered Oct 06 '22 00:10

Alexander Malfait


Smarty


I've found it to be fast, easy to use, and easy to install (even in a shared-hosting environment). It also doesn't require that you use validating XHTML which is handy sometimes (although I think the template engines that do require valid XHTML are probably faster.)

It's really nice to have your content in one place and code somewhere else.

Plus you're not limited to just HTML. I've used Smarty to generate XML and even SQL.

like image 43
Mark Biek Avatar answered Oct 05 '22 22:10

Mark Biek


To follow up on what Alex said, I suggest taking a look at Rasmus Lerdorf's article The no-framework PHP MVC framework.

Rasmus Lerdorf is the guy who created PHP.

like image 33
Powerlord Avatar answered Oct 05 '22 23:10

Powerlord