Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use a templating engine with a framework?

I recently discovered the PHP framework Kohana (which is awesome) and was reading a thread about using it in conjunction with a templating engine such as Smarty or Twig. My question is why bother? Surely an MVC framework, by definition, is a templating engine. Even "raw" PHP is, arguably, a templating engine. What possible benefits are there of adding another level of abstraction on top of what's already present in a framework such as Kohana?

EDIT - I realise that an MVC framework isn't the same thing as a templating engine, but surely the V part does the same job? Perhaps a better way of phrasing things would be; why add an templating engine on top of the V part of an MVC framework?

like image 224
Mathew Avatar asked Nov 05 '09 02:11

Mathew


People also ask

What is an advantage to using a templating engine?

A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page.

When should you use a templating engine?

Template engines are used when you want to rapidly build web applications that are split into different components. Templates also enable fast rendering of the server-side data that needs to be passed to the application. For example, you might want to have components such as body, navigation, footer, dashboard, etc.

Are templating engines necessary?

You actually dont need them, but they have a lot of features that makes your pages more dynamic..

What is the difference between framework and template?

Frameworks are more complex than template engines. A framework can contain a template engine but not reverse. A framework can help you in numberless ways to build your (web) application. A template engine is simply used to parse variables into your preformatted html template.


1 Answers

I have two really good reasons I can think of for doing this...

  1. Creating markup that is repeated throughout the site in a consistent format is easier, plus you can update it later without a lot of grepping.
  2. If this is for a real company, the people determining content aren't likely to be really familiar with HTML, much less PHP. Having a simple template language that keeps styles looking the right way and generates valid markup without much code knowledge is really handy.
like image 166
coreyward Avatar answered Oct 04 '22 11:10

coreyward