Skip to content

Commit

Permalink
Reapply "Adds renderContent universal filter in Render Plugin. Fixes
Browse files Browse the repository at this point in the history
…#3370"

This reverts commit 2d945b3.
  • Loading branch information
zachleat committed Jul 18, 2024
1 parent 2d945b3 commit 8fb27e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Plugins/RenderPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function eleventyRenderPlugin(eleventyConfig, options = {}) {
let defaultOptions = {
tagName: "renderTemplate",
tagNameFile: "renderFile",
filterName: "renderContent",
templateConfig: null,
accessGlobalData: false,
};
Expand Down Expand Up @@ -363,6 +364,11 @@ function eleventyRenderPlugin(eleventyConfig, options = {}) {
});
}

// Filter for rendering strings
if (opts.filterName) {
eleventyConfig.addAsyncFilter(opts.filterName, _renderStringShortcodeFn);
}

// Render File
// use `false` to opt-out
if (opts.tagNameFile) {
Expand Down
7 changes: 7 additions & 0 deletions test/TemplateRenderPluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,10 @@ test.skip("Use liquid in njk (access to all global data)", async (t) => {
let html = await getTestOutputForFile("./test/stubs-render-plugin/liquid-global.njk");
t.is(html, `globalHi`);
});

test("Render front matter via renderTemplate (njk)", async (t) => {
let html = await getTestOutputForFile("./test/stubs-render-plugin/nunjucks-frontmatter.njk", (eleventyConfig) => {
eleventyConfig.addShortcode("test", () => "test content")
});
t.is(html, "test content");
});
5 changes: 5 additions & 0 deletions test/stubs-render-plugin/nunjucks-frontmatter.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
hi: "{% test %}"
---
{{ hi | renderContent("njk") }}
{# {% renderTemplate "njk", hi %}{{ _ }}{% endrenderTemplate %} #}

0 comments on commit 8fb27e1

Please sign in to comment.