{$hello} or <?=$hello?>

Tagscript-style syntax vs. PHP syntax

Previous versions of ProcessWire, as well as the CMSs that preceded it (like Dictator CMS) used a tagging syntax where you could reference a value in your template using a tag like {$title}. Everywhere that appeared, it would be replaced by the page's title field. It went a lot further than that, but this is a simple example.

As time has gone on, I've come to question the value of this, as {$title} is equivalent to <?=$title?> in PHP syntax. In that case, the tagged version is slightly shorter, but at what cost? When you start to realize the redundancy and inefficiency of the tagged version, it starts to look a lot less attractive. Despite writing such template engines in the past, I always reverted back to PHP syntax for the direct simplicity, and efficiency of it. I didn't want to start down the road of creating a new syntax for people to learn. Especially when I knew I wouldn't use it myself. You don't need to know PHP in order to use its syntax in a template, and much of the PHP syntax you learn is universal and non-proprietary. Tagged syntax seems to be based largely upon a myth.

This becomes more significant as you start working with loops and branches, where the tagged syntax can become significantly more verbose. And then even more significant when you need to manipulate values before output, or work with more complex data types. What you end up with is something like the Smarty template engine...  A new language to learn that is more complex than the language it was to replace (PHP).

In ProcessWire, I wanted to be sure that there was a high level of consistency, and lack of ambiguity in the API syntax. I didn't want to end up with a situation where sometimes you would use {$tags} and other times you would use PHP syntax. In my mind, that adds complexity and confusion. Add to that the overhead of another template engine, and I'm convinced that PHP itself is the best possible template engine. ProcessWire is designed with this in mind. That's not to say that we won't add some kind of tag-script for simple shortcuts in the future, but the template engine will always be PHP based.

Not convinced? Read this short article about template engines.

See also a code snippet of Expression Engine syntax compared with ProcessWire syntax.

Comments

  • KLOR

    KLOR 5 years ago 52

    I suggest that non-standard syntax is provide as extra modules to make the syntax engine future safe.

    So new syntax engines can be added on the fly - examples:

    * Dictator CMS syntax: {$hello} .

    * Mustache syntax: {{hello}}

    * EJS syntax: (just to illustrate the point - I am aware that EJS is JavaScript and not PHP).

    * Symfony/Twig syntax: {% block content %}{{ hello }}{% endblock %}

  • nik.jain

    nik.jain 4 years ago 54

    >In my mind, that adds complexity and confusion. Add to that the overhead of another template engine, and I'm convinced that PHP itself is the best possible template engine.

    THANK You! for this and processwire. :)

  • pio77

    pio77 3 years ago 52

    Another syntax, another engine, another problems. Php-like syntax is the best one. Thanks for this ProcessWire!

  • Claes

    Claes 2 years ago 00

    Totally makes sense to me. PHP will be there for ever(or for a very long time), template engines come and go.

  • Gavin

    Gavin 2 years ago 00

    Templating languages on a PHP website always bothered me. PHP does everything so well, it seems silly to introduce more complexity to save a couple characters in a echo statement.

  • Yannick Albert

    Yannick Albert 2 years ago 00

    https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#file-compiler-modules

  • George

    George 11 months ago 00

    The link in the line "Not convinced? Read this short article about template engines." is no longer valid. I believe the article you looking for is still available at archive.is/IBx2K

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.