javascripthtmlmeteormeteor-blazehtml5-template

How can I include an HTML <template> element within a Meteor Blaze Template?


I'm using Meteor, but would like to use some vanilla javascript/HTML code that uses the html template element.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template

When I try to include one inside a meteor template:

<template name="test2">
    <template id="test3">Some stuff i will clone in javascript</template>
</template>

Meteor displays the following error:

While processing files with templating (for target web.browser):
client/index.html:153: Expected one of: <body>, <head>, <template>

Is there a way to include these in a Meteor template? I am aware I can include them within the body tag but its a bit unwieldy.


Solution

  • Use a helper

    In a client side .js file

    Template.registerHelper('vanillaTemplate', () => {
        return '<template id="test3">Some stuff i will clone in javascript</template>'
    })
    

    In a client side .html file

    <template name="test2">
        {{> vanillaTemplate}}
    </template>