Skip to content

Instantly share code, notes, and snippets.

@kieranja
Last active February 16, 2021 22:01
Show Gist options
  • Save kieranja/99b85c0fe85639362c15c40d92f5cdac to your computer and use it in GitHub Desktop.
Save kieranja/99b85c0fe85639362c15c40d92f5cdac to your computer and use it in GitHub Desktop.
{%- macro classNames(classes) -%}
{%- set final = [] %}
{%- for class, isActive in classes.items() -%}
{% if isActive %}{% do final.append(class) %}{% endif %}
{%- endfor -%}
{%- if final|count -%}
{{ { "class": final | join(" ") }|xmlattr }}
{%- endif -%}
{%- endmacro -%}
<div {{ classNames({'is-open"/>': true, "is-closed": true, "another-class": true}) }}>
hey test
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment