Skip to content

Add front matter support to renderFile in the Render plugin #2712

@extrabright

Description

@extrabright

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like

I started using the renderFile option provided in the Render plugin: https://www.11ty.dev/docs/plugins/render/#renderfile. It works as expected, but when I use frontmatter in the rendered file, it doesn't seem to work.

It would be very helpful to have that and make it work 11tysh 💯

{% renderFile "file.njk", { data } %}

In the rendered file:

---
title: Some title
description: ...
---

Content for included file 

Describe alternatives you've considered

Before finding the Render plugin I created a custom tag for my 11ty projects which works similar, but I couldn't make it process the nunjucks shortcodes and filters inside the included file:

config.addNunjucksTag("inject", function(nunjucksEngine) {
   return new function() {
	this.tags = ["inject"];
	this.parse = function(parser, nodes) {
           const token = parser.nextToken()
	   const args = parser.parseSignature(null, true)

	    parser.advanceAfterBlockEnd(token.value)

	    return new nodes.CallExtensionAsync(this, 'run', args)
	}

	this.run = function(context, filePath, data, callback) {
		filePath = path.resolve('src/', filePath)

		// Allow usage without data passed to the tag
		if (callback == null) {
			callback = data
			data = null
		}

		fs.readFile(filePath, 'utf8', (err, str) => {

			if (err != null) return callback(err)

			var content = fm(str)
			var body = content.body

			let ret = nunjucksEngine.renderString(body, data, {
				path: filePath
			}, callback)

			ret = new nunjucksEngine.runtime.SafeString(ret);

			callback(null, ret);

		})
	};
   }();
});

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions