Thoughts on my new template language?
Posted
by
Ralph
on Programmers
See other posts from Programmers
or by Ralph
Published on 2011-01-07T20:36:39Z
Indexed on
2011/01/07
20:58 UTC
Read the original article
Hit count: 551
feedback
|template-language
Let's start with an example:
using "html5"
using "extratags"
html {
head {
title "Ordering Notice"
jsinclude "jquery.js"
}
body {
h1 "Ordering Notice"
p "Dear @name,"
p "Thanks for placing your order with @company. It's scheduled to ship on {@ship_date|dateformat}."
p "Here are the items you've ordered:"
table {
tr {
th "name"
th "price"
}
for(@item in @item_list) {
tr {
td @item.name
td @item.price
}
}
}
if(@ordered_warranty)
p "Your warranty information will be included in the packaging."
p(class="footer") {
"Sincerely," br @company
}
}
}
The "using" keyword indicates which tags to use. "html5" might include all the html5 standard tags, but your tags names wouldn't have to be based on their HTML counter-parts at all if you didn't want to.
The "extratags" library for example might add an extra tag, called "jsinclude" which gets replaced with something like <script type="text/javascript" src="@content"></script>
Tags can be optionally be followed by an opening brace. They will automatically be closed as the closing brace. If no brace is used, they will be closed after taking on element.
Variables are prefixed with the @
symbol. They may be used inside double-quoted strings. I think I'll use single-quotes to indicate "no variable substitution" like PHP does.
Filter functions can be applied to variables like @variable|filter
. Arguments can be passed to the filter @variable|filter:@arg1,arg2="y"
Attributes can be passed to tags by including them in ()
, like p(class="classname")
.
Some questions:
- Which symbol should I use to prefix variables? @ (like Razor), $ (like PHP), or something else?
- Should the @ symbol be necessary in "for" and "if" statements? It's kind of implied that those are variables.
- Tags and controls (like if,for) presently have the exact same syntax. Should I do something to differentiate the two? If so, what?
- Do you like the attribute syntax? (round brackets)
I'll add more questions in a few minutes, once I get some feedback.
© Programmers or respective owner