Question

I am looking for a good character pair to use for enclosing template code within a template for the next version of our inhouse template engine.

The current one uses plain {} but this makes the parser very complex to be able to distinguish between real code blocks and random {} chars in the literal text in the template.

I think a dual char combination like the one used in asp.net or php is a better aproach but the question is char character pair should I use or is there some perfect single char that is never used and thats easy to write.

Some criteria that needs to be fullfilled:

  • Cannot be changed by HTMLEncode, the sources will be editable through webbased HTML editors and plain textareas and need to stay the same no matter what editor is used.
  • Regex will be used to clean code parts after editing in an HTML editor that might have encoded the internal part of the code block like & chars.
  • Should be resonably easy to write on both english and swedish keyboard layout.
  • Should be a very rare combination, the template will generate HTML and Text and could include CSS and Javascript literal text with JSON, so any combination that might collide with those is bad unless very rare. That means that {{}} is out as it can occur in JSON.
  • The code within the code block will contain spaces, underscores, dollar and many more combinations, not only fieldnames but if/while constructs as well.
  • The parser is generated with Antlr

I am looking for suggestions and objections to find one or more combinations that would work i as many situations as possible, possibly multiple alternative pairs for different situations.

Was it helpful?

Solution

Template-Toolkit defaults to [% template directives %], which works reasonably well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top