I have a page with some variables defined in it, and I import a macro:
{% extends "layout.nunjucks" %}
{% set activePage = "iis" %}
{% set activeSubPage = "organos" %}
{% block content %}
<!--sub-nav-->
{% import 'macros/subnavigation.nunjucks' as subnav %}
{{subnav.active(activeSubPage)}}
<!--/sub-nav-->
{% endblock %}
Inside the macro, I want to check the content of the activePage variable:
````
{% macro active(activeSubPage='quienes-somos') %}
{% endif %}
{% endmacro %}
```
As activePage == 'iis', it should render 'subnav-1.nunjucks', but instead it renders
The question is: can I reference a variable in a macro, which is defined outside of it?
Thanks.
You need to import macro with current context, like so:
{% import 'macros/subnavigation.nunjucks' as subnav with context %}
Great, didn't know about that.
Thanks!
Most helpful comment
You need to import macro with current context, like so: