Skip to content

Pull fragments out of Nunjucks Templates for partial render.

Notifications You must be signed in to change notification settings

benkenawell/nunjucks-fragments

Repository files navigation

Nunjucks Template Fragments

Inspired by Carson Gross's Template Fragments Essay and unable to find a templating engine for Javascript that supported such a feature, I've decided to try and write one for Nunjucks.

This is not for production! Maybe some day, but today it would be ill advised to use. Feel free to fork and hack on it though.

Why Nunjucks?

It's been my favorite templating engine when I'm trying stuff out. It's inheritance is amazing, and it makes breaking templates into reusable pieces a breeze. However, like the essay states, there's something very satisfying about being able to stay in a single file that makes fragments appealing.

How

That's an excellent question... One that I hope to answer. I don't have a background in lexers, parser, etc. other than how far I am through Crafting Interpreters by Robert Nystrom. I'm excited to be learning more, but I'm more excited to have this functionality at my finger tips when using Turbo with Express

API Surface, Target

This isn't something I use at my dayjob, I hope it will be a proof of concept for those actually building Javascript Templating Engines, so we can have a feature like JStachio's Fragments via URI Fragment Notation.

I don't think that's something I'm able to bake into an engine like Nunjucks, so this package will likely be a renderFragment function, similar to jinja2-fragments for a long time.

Contributing

I'm happy to try and field issues, but know that this is something I may lose steam on, or find an implementation I find acceptable, but isn't widely useful.

About

Pull fragments out of Nunjucks Templates for partial render.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages