Jump to content
MakeWebGames

Template Engine


Guest

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...