Using variable in a macro
See original GitHub issueHi,
I want to use a macro in a layout, that renders a link list. I then want to pass a variable to that macro in every template that extends that layout, in order to add a class of “active” to one of the list links.
To do this, I have a nunjucks file with this code, which extends a layout and sets the variable:
{% extends "layout.nunjucks" %}
{% set activePage = "actualitat" %}
I’d like to use the value of the variable activeMenu in my layout.nunjucks file, where there’s this code, which doesn’t work:
{% import 'macros/navigation.nunjucks' as nav %}
{{nav.active({{ activePage }})}}
The macro I’m importing is:
{% macro active(activePage='home') %}
<ul class="menu">
<li><a href="/" class="{%if activePage == 'home' %}active{% endif %}">Home</a</li>
<li><a href="/actualitat/" class="{%if activePage == 'actualitat' %}active{% endif %}">Actualitat</a></li>
<li><a href="/estils/" class="{%if activePage == 'estils' %}active{% endif %}">Estils</a></li>
<li><a href="/contacte/" class="{%if activePage == 'contacte' %}active{% endif %}">Contacte</a></li>
</ul>
{% endmacro %}
How should I pass the value of the variable to the macro, so I have my link list with the class “active” added to the link I want?
Thanks.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Variables in Excel VBA (Easy Macros)
This chapter teaches you how to declare, initialize and display a variable in Excel VBA. Letting Excel VBA know you are using a...
Read more >Define Variables In VBA: Declare Variables And Assign Them ...
Detailed tutorial about defining variables in Excel VBA. Learn now how to declare variables, determine their scope and lifetime, and assign values to...
Read more >Variables in Macros VBA for Excel - Practical Guide
A variable is a name that you type into a Macro that you can use to store information, be it text or numbers....
Read more >Pass VBA Variables Between Macros - Excel Dashboards VBA
In Excel you can pass variables (an argument) between macros at run time. This allows you to have multiple modules and pass the...
Read more >AN INTRODUCTION TO MACRO VARIABLES ... - OARC Stats
changing three lines of code, is not necessary if you use a macro variable as a shortcut to represent the data set name......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just added the includeFile function/macro at the top of my comment. I’m not exactly sure how to do that in the template; can you give an example?