The RenderPlugin allows you to render Eleventy template strings or files from within another template using shortcodes or filters. This is useful for nesting templates or rendering dynamic content blocks.
Plugin Options
When adding the plugin via $config.addPlugin(RenderPlugin, options), you can provide the following:
tagName (string): The name of the shortcode used to render a template string. Defaults to renderTemplate.tagNameFile (string): The name of the shortcode used to render a template file. Defaults to renderFile.filterName (string): The name of the async filter used to render template strings. Defaults to renderContent.templateConfig (TemplateConfig): A configuration object.accessGlobalData (boolean): If true, the rendered template will have access to the parent template's data cascade. Defaults to false.
Usage Examples
Rendering a String (Shortcode/Tag)
If using Liquid or Nunjucks, you can use the tagName as a paired shortcode/tag:
{% renderTemplate %}
<p>This is dynamic content!</p>
{% endrenderTemplate %}
Rendering a File (Shortcode)
Use the tagNameFile to render an existing file on disk:
{% renderFile "path/to/template.njk", { key: "value" } %}
// Example of adding the plugin in your .eleventy.js config
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(RenderPlugin, {
tagName: 'myCustomRender',
accessGlobalData: true
});
};