Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 11ty.js Virtual Templates #3347

Closed
zachleat opened this issue Jul 4, 2024 · 4 comments
Closed

Add support for 11ty.js Virtual Templates #3347

zachleat opened this issue Jul 4, 2024 · 4 comments

Comments

@zachleat
Copy link
Member

zachleat commented Jul 4, 2024

Related: #1612

@zachleat
Copy link
Member Author

zachleat commented Jul 4, 2024

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}.`;
  }
});

@VividVisions
Copy link
Contributor

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);

@zachleat
Copy link
Member Author

zachleat commented Jul 5, 2024

@VividVisions any of the 11ty.js types would work there: https://www.11ty.dev/docs/languages/javascript/

@zachleat zachleat added the needs-documentation Documentation for this issue/feature is pending! label Sep 20, 2024
zachleat added a commit to 11ty/11ty-website that referenced this issue Sep 26, 2024
@zachleat
Copy link
Member Author

Temporary docs preview URL building here: https://11ty-website-git-v3-11ty.vercel.app/docs/virtual-templates/#javascript

@zachleat zachleat added feature: 🥽 virtual templates and removed needs-documentation Documentation for this issue/feature is pending! labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants