Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-01T18:01:56.823Z
Answers.LastActivityDate: 2021-03-02T09:30:29.730Z
Answers.LastEditDate: 2021-03-02T09:30:29.730Z
Answers.UserDisplayName: dmatthams
Body: <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>
  
Tags: <craft3><macro><params>
Title: Passing multiple arguments to a macro?
ThreadText: # 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 %}
  
  ```
  
  ```
  <a href="/the-url" class="{{ macros.is_active('test1', 'test2', 'test3') }}">Link Title</a>
  
  ```
  
  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 #}
  <a href="/the-url" class="{{ macros.is_active(['test1', 'test2', 'test3']) }}">Link Title</a>
  
  ```
  
  
  ---
  
  