Skip to content

Add support for 11ty.js Virtual Templates #3347

Closed

Description

@zachleat

Related: #1612

Activity

  1. added this to the Eleventy 3.0.0 milestone on Jul 4, 2024
  2. zachleat commented on Jul 4, 2024

    @zachleat
    MemberAuthor

    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}.`;
      }
    });
  3. VividVisions commented on Jul 5, 2024

    @VividVisions
    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);
  4. zachleat commented on Jul 5, 2024

    @zachleat
    MemberAuthor

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

  5. added a commit that references this issue on Jul 8, 2024
    9d1572c
  6. added a commit that references this issue on Sep 26, 2024
  7. zachleat commented on Sep 26, 2024

    @zachleat
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions