<p>You might be better off sending the values as an array, then you will only need one parameter.</p>
<pre><code>{# Change the macro to check for the value in an array #}
{% macro is_active(segments) %}
    {% if craft.app.request.getSegment(2) in segments %}active{% endif %}
{% endmacro %}
</code></pre>
<pre><code>{# Send an array to the macro #}
&lt;a href=&quot;/the-url&quot; class=&quot;{{ macros.is_active(['test1', 'test2', 'test3']) }}&quot;&gt;Link Title&lt;/a&gt;
</code></pre>

CC BY-SA 4.0
2021-03-01T18:01:56.823Z
2021-03-02T09:30:29.730Z
2021-03-02T09:30:29.730Z
dmatthams
<p>I have a link on a website that i'd like to set a class of active on, based on different segments.</p>
<pre><code>{% macro is_acitve(segment) %}
    {% if craft.app.request.getSegment(2) == segment %}active{% endif %}
{% endmacro %}
</code></pre>
<pre><code>&lt;a href=&quot;/the-url&quot; class=&quot;{{ macros.is_active('test1', 'test2', 'test3') }}&quot;&gt;Link Title&lt;/a&gt;
</code></pre>
<p>It's not working. How would I go about this ?</p>

<craft3><macro><params>
Passing multiple arguments to a macro?
# Passing multiple arguments to a macro?

(Asked by: username_0 on 2021-02-26)

I have a link on a website that i'd like to set a class of active on, based on different segments.
{% macro is_acitve(segment) %}
    {% if craft.app.request.getSegment(2) == segment %}active{% endif %}
{% endmacro %}

Link Title

It's not working. How would I go about this ?

**Tags:** craft3, macro, params

---

## 1 answers

### Answer by username_1 on 2021-03-01. Score: 2 | Accepted answer

You might be better off sending the values as an array, then you will only need one parameter.
{# Change the macro to check for the value in an array #}
{% macro is_active(segments) %}
    {% if craft.app.request.getSegment(2) in segments %}active{% endif %}
{% endmacro %}

{# Send an array to the macro #}
Link Title


---

