Template syntax for users - is there a right way to do it?

Posted by RickM on Programmers See other posts from Programmers or by RickM
Published on 2012-11-20T09:32:55Z Indexed on 2012/11/20 11:26 UTC
Read the original article Hit count: 219

Filed under:
|
|
|
|

Ok,

I'm in the middle of building a saas system, and as part of that, the hosted clients need to be able to edit certain layout templates, baqsically just html, css and javascript files.

I'm obviously going to be wanting to use a template syntax here as it would be dumb to let people execute PHP code, so in this instance template syntax does need to be used.

I know that in the grand scale of things, this is a very minor thing, but what template syntax do you use, and why? Is there one that's considered better than others? I've seen all sorts being used with no real consistency, for example:

Smarty Style:

{$someVar}
{foreach from="foo" item="bar"}
    {$bar.food}
{/foreach}

ASP Style:

{% someVar %}
{% foreach foo as bar %}
    {% bar.food %}
{% endforeach %}

HTML Style:

<someVar>
<foreach from="foo" item="bar">
    <bar:food>
</foreach>

PyroCMS/FuelPHP "LEX" Style:

{{ someVar }}
{{ foreach from="foo" item="bar" }}
    {{ bar:food }}
{{ endforeach }}

Obviously these arent 100% accurate (for example, LEX is used alongside PHP for loops), and are only to give you an example of what I mean. What, in your opinion would be the best one (if any) to go with. I ask this bearing in mind that people using this are likely to be novice users.

I did look around at a bunch of hosted CMS and E-Commerce systems as these seem to make use of user-editable templates, and most seem to be using some form of their own syntax.

I should note that whatever style I end up going with, it will be with a custom template handler due to the complexity of the system and how template files are stored. Plus I'd not want to touch the likes of Smarty with a barge pole!

© Programmers or respective owner

Related posts about php

Related posts about syntax