Many template systems provide a programmatic mechanism (usually a simple
function call) that can be used to perform template expansion based on
passing the template string and some object that serves as mapping
dictionary, e.g.:

    expand(`Hello ${x} and ${y}!`, {x: 10, y: 12});
    // ==> Hello 10 and 12!

>From what I've seen of drafts of ES6 template strings, templates are
expanded automatically by evaluating the expressions enclosed in ${...} at
the point where the template string literal appears.

Do ES6 templates offer this more conventional, explicit,
programmer-controlled form of expansion in any form?  It doesn't appear so
from my reading of the draft specs, but I thought I'd check.  And it's
somewhat understandable, since any expression can appear inside ${...}, not
just variable identifiers.

My particular application is that I want to use a template system to
construct SQL queries in a modular way.  For this particular application I
want programmatic control over when and how the expansion happens and won't
have the escaped template expressions in scope at the point where the
template string literal appears.  So I'll probably just use ES6 template
strings because they can span multiple lines, but use Mustache.js instead
of ES6 for expansion.  But I'd be happy to learn of a better alternative.

Thanks,

   -Antony Courtney
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to