HTML Template Engine Syntax Question

3 replies

I am creating a HTML template engine for some new software I am creating and need some advice on the syntax.

I need a reliable way to notify to the template engine that "here comes a command".

The templates will be parsed to find commands that will be executed by the templating engine.

After that, the commands will be substituted for some valid html or text.

I have seen many different types of syntaxes for templating engines, and I just want to what is the best way to denote commands/substitutions in the template code.

Examples of syntaxes are [[ tempate code ]], { { template code } } <% template code %>, { tempate code }.

What should I select?

#engine #html #question #syntax #template
  • Profile picture of the author Brandon Tanner
    If you are developing the software, then why wouldn't you be able to use whatever syntax you want? (as long as the syntax doesn't conflict with your programming language, of course).

    That said, I wouldn't use single curly brackets, because those are pretty common in CSS, Javascript, PHP, etc. Come to think of it, I can think of a few instances where double curly brackets might exist naturally too.

    I think you'd probably be safe with either double square brackets, or <%

    But if you wanted to be extra careful, then you could do triple, like [[[ etc.

    {{ DiscussionBoard.errors[7856909].message }}
    • Profile picture of the author olavlind
      Thanks brandon. I can implement whatever I want. The problem is conflicts with html and scipting languages and other things that can appear naturally in an html page.

      Double square is what I have used in other projects (email merge etc.) so I will do that.

      Might change to tripple square brackets if conflicts appear later on.

      Thanks for your answer.

      {{ DiscussionBoard.errors[7862969].message }}
      • Profile picture of the author jminkler
        Why not just use an available templating engine? Don't reinvent wheels, you aren't the first programmer to solve this problem.
        {{ DiscussionBoard.errors[7863389].message }}

Trending Topics