You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for Nunjucks! On the GOV.UK Prototype Kit we use it extensively, and one thing we do is load in macros through a custom plugin system.
We do that in a base layout file (lets say that is called base.njk).
I'm trying to wrap some macros from one plugin to add functionality to them (set some default values). So I want to do something like this (slightly simplified):
{% set _myComponent = myComponent %}
{% macro myComponent(option1, option2) %}
{% set option2 = option2 or "value2" %}
{{ _myComponent(option1, option2) }}
{% endmacro %}
If I do this in the same file that myComponent is imported in, this works. However due to constraints in the plugin system I can't do it there, so I'm trying to do it in a child layout that extends base.njk. If I do that it stops working, it seems myComponent is available as a macro to run, but can't be reassigned (it says myComponent is undefined). So doing it with a new name works but isn't what I need:
{% macro myNewComponent(option1, option2) %}
{% set option2 = option2 or "value2" %}
{{ myComponent(option1, option2) }}
{% endmacro %}
Is there a way to achieve 'wrapping' like this in a child layout, or method other than reassigning it in the same layout?
The text was updated successfully, but these errors were encountered:
Thanks for Nunjucks! On the GOV.UK Prototype Kit we use it extensively, and one thing we do is load in macros through a custom plugin system.
We do that in a base layout file (lets say that is called
base.njk
).I'm trying to wrap some macros from one plugin to add functionality to them (set some default values). So I want to do something like this (slightly simplified):
If I do this in the same file that myComponent is imported in, this works. However due to constraints in the plugin system I can't do it there, so I'm trying to do it in a child layout that extends
base.njk
. If I do that it stops working, it seemsmyComponent
is available as a macro to run, but can't be reassigned (it saysmyComponent
is undefined). So doing it with a new name works but isn't what I need:Is there a way to achieve 'wrapping' like this in a child layout, or method other than reassigning it in the same layout?
The text was updated successfully, but these errors were encountered: