Closed zachleat closed 4 months ago
Shipping with 3.0.0-alpha.15. Pass in the raw JavaScript as the virtual template content, like so:
eleventyConfig.addTemplate("virtual.11ty.js", function(data) {
return `this is a test ${data.page.url}.`;
});
eleventyConfig.addTemplate("virtual.11ty.js", {
data: () => ({ var: 2 }),
render: function(data) {
return `this is a test ${data.var}.`;
}
});
Awesome! So, I guess using JS classes as templates (with data
and render
methods) will also be as easy as this:
import MyTemplateClass from 'mytemplate.js';
const template = new MyTemplateClass({ options: { /* ... */}});
eleventyConfig.addTemplate('virtual.11ty.js', template);
@VividVisions any of the 11ty.js types would work there: https://www.11ty.dev/docs/languages/javascript/
Temporary docs preview URL building here: https://11ty-website-git-v3-11ty.vercel.app/docs/virtual-templates/#javascript
Related: #1612