I'm developing a templating language, and now I'm trying to decide on what I should do with quotes. I'm thinking about having 3 different types of quotes which are all handled differently:

                     backtick `     double quote "     single quote '
expand variables         ?              yes                 no
escape sequences        no              yes                  ?
escape html             no              yes                 yes


Backticks are meant to be used for outputting JavaScript or unescaped HTML. It's often handy to be able to pass variables into JS, but it could also cause issues with things being treated as variables that shouldn't. My variables are PHP-style ($var) so I'm thinking that might mess with jQuery pretty bad... but if I disable variable expansion w/ backticks then, I'm not sure how would insert a variable into a JS code block?

Single Quotes

Not sure if escape sequences like \n should be treated as literals or converted. I find it pretty rare that I want to disable escape sequences, but if you do, you could use backticks. So I'm leaning towards "yes" for this one, but that would be contrary to how PHP does it.

Double Quotes

Pretty certain I want everything enabled for this one.


I'm also thinking about adding modifiers like @ or r in front of the string that would change some of these options to enable a few more combinations. I would need 9 different quotes or 3 quotes and 2 modifiers to get every combination wouldn't I?

My language also supports "filters" which can be applied against any "term" (number, variable, string) so you could always write something like

"blah blah $var blah"|expandvars


"my string"|escapehtml

Thoughts? What would you prefer? What would be least confusing/most intuitive?

  • My first thought is why are you doing this? At least one version of templating is already avaliable for most modern languages. What problems do you perceive with the existing facilities? Mar 3, 2011 at 3:00
  • 2
    @kevin: every time I post a question about this, someone such as yourself says something like that. I'm well aware that there are plenty of good templating engines out there already, and mine will probably never take off, and I'm perfectly cool with that. this is part of a larger project, for an entire framework, and every one I've tried seems to have flaws. i just want to build something that meets my needs. that is all.
    – mpen
    Mar 4, 2011 at 1:57
  • 1
    @kevin: specifically, with regards to templating languages... nothing major. Django has some pretty weak support for including partials: you can include them just fine, but if you want to pass in any variables, you have to wrap the whole block in a dozen 'using' statements, which is just horrid. A cross between Haml and Razor would be nice (essentially what I'm building)
    – mpen
    Mar 4, 2011 at 2:00

1 Answer 1


I know that I'm not realy answer your question, but just give you a suggestion.

For templating I'm planning to give PHPQuery a try (for one of my big projects at work), PHPQuery is a port of jQuery to PHP, so you can have a simple HTML as a template, without the need of special characters or string templates in it, read it in PHP and use jQuery like selectors to manage what you need to change in the DOM of that HTML file. I use this approach for some small projects, I don't know if it's faster or slower than classic templating approaches for large projects, but seems pretty easy to implement and use.

  • Interesting idea... since it's all server side, there's still no reliance on JS. I like that. I'm planning on adding some stuff where you can set attributes relative to each other.. like, say, half the parent's width, or something like that. I'd prefer to keep most of it inline I think, though, rather than having a simple markup and then doing post-processing on it.
    – mpen
    Mar 18, 2011 at 0:52
  • @Ralph, I'm glad I could help :)
    – Radu Maris
    Mar 18, 2011 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.