Funny, I was just thinking about this the other day. I had managed to
convince myself that double-braces don't really appear in practice in
many contexts, though, so it wasn't really necessary to support. But
latex is a good point; I had forgotten about it.
My plan at the time was to think about introducing a new built-in
variable, BI_2B or some such, that evaluates to "{{". How messy would
that be for latex? Probably pretty messy.
The idea of specifying alternative delimiters on a per-template basis
makes sense to me. What do folks think of the following syntax?
{{=AAA BBB=}}
This says, 'replace {{ and }} with AAA and BBB'. We can either
require this to be first thing in the file, or just allow it wherever,
and have it apply to all subsequent text. I like the latter if the
implementation isn't too annoying. So you could do
{{=<< >>=}} I need {{ but can use <<MARKUP>> markup anyway.
<<={{ }}=>> {{! back to normal! }}
AAA and BBB can be any characters except for whitespace, :, and =.
They can be the equal too:
{{=| |=}} I need {{ but can use |MARKUP| markup anyway.
|={{ }}=| {{! back to normal! }}
} Tags label the specific template file, so if you are using the same
} template filling code for different output formats (=different
} template files), you can get information what kind of format is on
} just now. I use it to deliver different date formats in RSS and Atom
} feeds.
I'm not sure I understand this suggestion. Can you give a specific
example?
} And last, I found it very useful being able to specify 'separator
} text' for sections.
Yes, I can see how this would be very useful. It seems like common
functionality, and annoying to work around. What API did you use? Do
you specify the separator text inside the template, or on the C (Java)
side via a sectionSeparator() function call or some such?
craig
Actually, BI_2B would be built into the template dictionaries, just
like BI_SPACE etc are now. I don't think using it will be
particularly tricky, it's just a matter of how messy the syntax is.
} My first line for the RSS template file is
} {{ }} XML RSS
} compared to the Atom template file first line
} {{ }} XML ATOM
} . The template filling code asks the template object for tags and
} decides for the date format:
} if(template.hasTag("RSS")) {
} dict.addStringValue("DATE",rssdf.format(art.getTime()));
} else if(template.hasTag("ATOM")) {
} dict.addStringValue("DATE",atomdf.format(art.getTime()));
} else {
} dict.addStringValue("DATE",normaldf.format(art.getTime()));
} }
Yeah, I think the suggested way do to this would be using modifiers.
So your template-filling code would look like this:
dict.addStringValue("DATE", art.getTime());
and your atom template would have text like
{{DATE:x-format-date=atom}
vs rss template which says
{{DATE:x-format-date=rss}
or whatever.
How well would that work for you? We're moving towards a model where
presentation-details like this are specified in the template rather
than the code, so I think this custom modifier approach is nice if it
works.
} Thinking that the separator text is layout language material, it
} must be specified in the template.
Yeah, I agree. Doing it as a modifier is definitely easy!, but you're
right it's limiting in ways that will probably be annoying to someone
in the future. I'll think if there's a clear, more general way to
implement something like this.
craig
That's not true, actually. The template language currently supports
\oneargumentmacro{{{ARG}}}
just fine -- give it a try!
Does that affect how you feel about {{BI_2B}}? It really is the
easiest solution, so if it works for people who need it, I'm very
happy to go that route. :-)
} > and your atom template would have text like
} > {{DATE:x-format-date=atom}
} > vs rss template which says
} > {{DATE:x-format-date=rss}
} > or whatever.
}
} That is surely the right way. But the modifier coding has to be
} somewhere in the library, and one might come up with a very special
} and private distinction between different templates, that nobody would
} put in the Google library.
Again, not really true -- ctemplate supports user-defined modifiers:
You can register a custom modifier with the template system. But
you're right this is a relatively recent addition to the ctemplate
system, so maybe not everyone is familiar with it yet.
} If you want to separate presentation details you would have
} ultimately to have a presentation programming language.
This is an excellent summary of what distinguishes ctemplate from
other temlpate systems: its rejection of this approach. As you point
out, it leads to a slippery slope. What's the point of separating out
temlpates from code if templates just become a new type of code?
While ctemplate has things like variables and loops and even a form of
conditional, they are set up and controlled entirely within the
programming language (c++ in this case), not within the template
markup language. That won't change in ctemplate; for folks who are
looking for that, there are already plenty of template languages with
that model to choose from.
craig