Guest Posted June 23, 2013 Posted June 23, 2013 Hey! Just curious as to others opinions on template engines and which one they prefer, with my upcoming project I am debating whether to even use one. I am thinking of either none or using Smarty. The project will be fully open source, so what are your opinions? Should it be like Wordpress and MCC with pure PHP in the templates, or should it be like ezRPG using Smarty? Opinions are appreciated. Quote
LeeMason Posted June 23, 2013 Posted June 23, 2013 I've been playing around with the PHP implementation of Moustache and I think it's awesome. Quote
Aventro Posted June 23, 2013 Posted June 23, 2013 ezRPG is dropping support of Smarty in the coming big update. We considered Twig but decided to go with our own template engine. Quote
Guest Posted June 23, 2013 Posted June 23, 2013 ezRPG is dropping support of Smarty in the coming big update. We considered Twig but decided to go with our own template engine. Why would yo uuse your own when there are very good other ones out there? Quote
Aventro Posted June 23, 2013 Posted June 23, 2013 Why would yo uuse your own when there are very good other ones out there? When we discussed the View, we came to the conclusion to make a more lightweight solution. Quote
Guest Posted June 23, 2013 Posted June 23, 2013 When we discussed the View, we came to the conclusion to make a more lightweight solution. Hmmm ok, will your engine auto escape vars and such? Will it be able to do loops? Quote
SRB Posted June 23, 2013 Posted June 23, 2013 Why reinvent the wheel when there are great template systems already out there? Throwing TWIG via a class, such as I have, requires nothing more than something like this, once integrated: PHP: <?php include_once('initiate.php'); login_required(); $sql = "SELECT `name`, `aiport`, `cost` FROM `locations` ORDER BY `cost` ASC"; $loc = $db->fetchALL($sql); $temp = new Template(); $temp->assign('locations', $loc) ->display('template/locations/file.php'); HTML (To use loop etc, only) <table class="table table-bordered"> {% for loc in locations %} <tr> <td>{{ loc.name }}</td> <td>{{ loc.airport }}</td> <td>${{ loc.cost|currency }}</td> </tr> {% endfor %} </table> Fairly simple and lightweight really Quote
Alan Posted June 23, 2013 Posted June 23, 2013 Interesting to note that nobody has asked to what purpose the templating system will be put to. An "open-source project" does not yield many clues, but there are many different answers based on the type of project. For example, consider a pretty much static set of web pages; assuming data can be pre-fetched ie: vis standard GET/POST methods, AND assuming the pages change very little, is there any need for a template system outside of keeping computational logic separate from display logic? In a business application where pages may need complex rules to render based on prior selection of say forms, especially if many parts are shared throughout the application, then there is a strong case for templating. As for games, while they exhibit similar problems, they usually need to be fast - which might suggest staying away from things like Smarty. Personally, I'm with Guest here; Twig is an excellent all-round tool, which is highly extensible offering superb facilities along with the added bonus of being similar to Jinja2 making portability of templates between scripting languages an added feature. Personally, I'd start by looking at exactly what the project is going to be doing; examine how often the templates will need to go through a ""compilation"" stage, and what sort of facilities might be needed outside of the very basic variable, loop and conditional elements common to most. There's also the point about who is going to editing templates. Users? Staff? Developers? Each will introduce their own special take on which system is finally used, and may well be the driving force between template engine selection. - - - Updated - - - Interesting to note that nobody has asked to what purpose the templating system will be put to. An "open-source project" does not yield many clues, but there are many different answers based on the type of project. For example, consider a pretty much static set of web pages; assuming data can be pre-fetched ie: vis standard GET/POST methods, AND assuming the pages change very little, is there any need for a template system outside of keeping computational logic separate from display logic? In a business application where pages may need complex rules to render based on prior selection of say forms, especially if many parts are shared throughout the application, then there is a strong case for templating. As for games, while they exhibit similar problems, they usually need to be fast - which might suggest staying away from things like Smarty. Personally, I'm with Guest here; Twig is an excellent all-round tool, which is highly extensible offering superb facilities along with the added bonus of being similar to Jinja2 making portability of templates between scripting languages an added feature. Personally, I'd start by looking at exactly what the project is going to be doing; examine how often the templates will need to go through a ""compilation"" stage, and what sort of facilities might be needed outside of the very basic variable, loop and conditional elements common to most. There's also the point about who is going to editing templates. Users? Staff? Developers? Each will introduce their own special take on which system is finally used, and may well be the driving force between template engine selection. Quote
Curtis Delicata Posted June 26, 2013 Posted June 26, 2013 Mustache is good, we use it for Modular Gaming. https://github.com/bobthecow/mustache.php Quote
Guest Posted June 26, 2013 Posted June 26, 2013 Mustache is good, we use it for Modular Gaming. https://github.com/bobthecow/mustache.php What is modular gaming? And what benefits does it have compared to twig and smarty? Quote
Aventro Posted June 26, 2013 Posted June 26, 2013 Hmmm ok, will your engine auto escape vars and such? Will it be able to do loops? I don't know. Honestly, I was one of the developers to actually want to use Twig. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.