4 ms·
How do PHP people handle templating simply? Edit: Perhaps I worded my question wrong. How do PHP programmers try and keep to DRY (ala layouts and view template
by runjake 14y ago
How do PHP people handle templating simply?
Edit: Perhaps I worded my question wrong. How do PHP programmers try and keep to DRY (ala layouts and view templates)?
- tlack 14y agoSmarty is the default choice, but of course you can simply require("tmpl/$LANG/index.php") - PHP's short tags like <?=$name;?> are almost as simple as Handlebar's.
- Ezku 14y agoSince PHP is a template language at heart, they go ahead and use PHP. For PHP folk, I guess the question is: how do people handle templating simply in other languages, since they can't use the host language itself for that? EDIT: Disclaimer: I'm a PHP guy trying to make a break for it, and the question was both rethorical and tongue-in-cheek.
- derpmeister 14y agoI prefer Mustache, but there are plenty of alternatives. http://mustache.github.com/ http://mustache.github.com/
- jackalope 14y agoIn Python, I've always used string substitution. I've never understood the need for a special templating system when it's already built into the language: template = """<boilerplate html>%(greeting)s</boilerplate html>""" parts = {'greeting': "Hello, World!"} page = template % parts I create my site-wide template in a module and never have to look at it again, so my application code is mostly logic. When I have to work on PHP or Coldfusion, I don't understand how people can bear to have the logic hidden in a markup language that's mixed up with another markup language. Many can't, and that's why there are templating engines for what are essentially template-based languages.
- dave007 14y agoSmarty, dwoo, moustache, some frameworks have their own engine (codeigniter for one). It's pretty much the same as other languages unless you're still one of the people who embed piles of php code in the templates.
- wvenable 14y agoPretty much every PHP framework is MVC. Sometimes the view is just a separate PHP file and sometimes it's some kind of template language.
- mhitza 14y agoPlain PHP with framework helpers, or Twig.