Encapsulated Eleventy/Nunjucks components with macros (by Trys Mudford)

Direct Link

Trys shows us how to use the Nunjucks macro to create encapsulated components. This works out less leaky and more predictable than an include preceded by variables assigned with set.

Trys’s solution allows us to render components like so:

{{ component('button', {
text: 'Press me'
}) }}

{# Output #}
<button type="button">Press me</button>
External Link Bookmark Note Entry Search