Skip to main content
added 147 characters in body
Source Link
dmatthams
  • 2.5k
  • 11
  • 19

You can sendmight be better off sending the values as an array to the macro, so: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>

You can send an array to the macro, so:

{% macro is_active(segments) %}
    {% if craft.app.request.getSegment(2) in segments %}active{% endif %}
{% endmacro %}
<a href="/the-url" class="{{ macros.is_active(['test1', 'test2', 'test3']) }}">Link Title</a>

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>
Source Link
dmatthams
  • 2.5k
  • 11
  • 19

You can send an array to the macro, so:

{% macro is_active(segments) %}
    {% if craft.app.request.getSegment(2) in segments %}active{% endif %}
{% endmacro %}
<a href="/the-url" class="{{ macros.is_active(['test1', 'test2', 'test3']) }}">Link Title</a>