how to delay interpolation of template strings?

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Dec 16 05:53:26 PST 2014


that's necessary for everything that has multi-language support ( at least
the way it's done these days ) hence my snippet that makes
interpolation/templating straight forward with dynamic strings.

Down the gist you also have CSP meta tags too to include it as inline
resource once + it scales a bit more than what Alex shown above since you
don't need to write logic in the string itself or name function arguments,
you just pass the object and you are good to go.

Hope that helps but I'm also curious to know if there is actually a way
using ES6 templates.
Maybe we are missing something.

Regards


On Tue, Dec 16, 2014 at 11:48 AM, Niloy Mondal <niloy.mondal84 at gmail.com>
wrote:
>
> Can this be considered for a feature request? Provision in the language to
> dynamically construct template strings and interpolate them.
>
> On Tue, Dec 16, 2014 at 4:48 PM, Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>>
>> irony ... I think you would need to evaluate the template string inline
>> in order to interpolate its result ...
>>
>> OR
>>
>> you just go for this method which also works down to ES3 engine:
>> https://gist.github.com/WebReflection/8f227532143e63649804
>>
>> Regards
>>
>> On Tue, Dec 16, 2014 at 10:01 AM, Niloy Mondal <niloy.mondal84 at gmail.com>
>> wrote:
>>
>>> Thanks, this would work.
>>>
>>> How can I construct a template string dynamically? Like reading the
>>> template from a file/database and then interpolate it.
>>>
>>> On Tue, Dec 16, 2014 at 2:29 PM, Claude Pache <claude.pache at gmail.com>
>>> wrote:
>>>>
>>>>
>>>> Le 16 déc. 2014 à 09:27, Niloy Mondal <niloy.mondal84 at gmail.com> a
>>>> écrit :
>>>>
>>>> I want to define a template string using backquotes in a different file
>>>> and then have it interpolated with actual values in a different file. How
>>>> can I do it?
>>>>
>>>>
>>>> Just enclose it in a function:
>>>>
>>>> ```javascript
>>>>    function foo(a) {
>>>>         return `some template ${a}`
>>>>     }
>>>>
>>>>     foo("bar") // will evaluate `some template ${"bar"}`
>>>> ```
>>>>
>>>> —Claude
>>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141216/e09a4e2e/attachment.html>


More information about the es-discuss mailing list