Template strings and templates

Claus Reinke claus.reinke at talk21.com
Fri Aug 3 01:25:54 PDT 2012


>    let tmpl = html`
>    <table>
>        $for address in addresses ${
>            html`<tr>${"first"}</tr><tr>${"last"}</tr>`
>        }
>    </table>`;

let tmpl = addresses => html`
    <table>
    ${addresses.forEach(address=>
            html`<tr>${address.first}</tr><tr>${address.last}</tr>`
        ).join('\n')
    }
    </table>`

would be my guess? Similarly for the localization example
in the blog post: arrow functions should make it relatively 
painless to make the template parameters explicit.

Of course, building HTML from nested templates is not the
same as filling a flat HTML template with user input, so I'm
not sure what the implicit encoding of template parameters
will do to this approach. 

Does this make sense?
Claus

>    // Use
>    console.log(tmpl({
>        addresses: [
>            { first: Jane, last: Bond },
>            { first: Lars, last: Croft },
>        ]
>    }));

 


More information about the es-discuss mailing list