Last active
March 4, 2022 16:08
-
-
Save bartwttewaall/8b98ecde3fe0256cb4cc5ed8d7a087ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set address = { firstName: 'Stack', lastName: 'Overflow', address: 'here', zipCode: '1234' } %} | |
{% set addressLines = address|keys|reduce((carry, key) => carry|merge({ (key): attribute(address, key) }), []) %} | |
{# results in: [ 'firstName' => 'Stack', 'lastName' => 'Overflow', 'address'=> 'here', 'zipCode' => '1234' ] #} | |
{% set allowedKeys = ['firstName', 'lastName', 'address'] %} | |
{% for key, line in addressLines|filter((v, k) => k in allowedKeys) %} | |
{{ line }}<br/> | |
{% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro writeHtmlArguments(options) %} | |
{% set parts = options|keys|reduce((carry, key) => carry|merge({ (key): attribute(options, key) }), []) %} | |
{% for key, value in parts %} | |
{{ key|kebab ~ '=' ~ value }} | |
{% endfor %} | |
{% endmacro %} | |
{# example usage #} | |
{% set options = { | |
class: "theme-dark", | |
dataHijacking: "off", | |
dataAnimation: "scaleDown" | |
} %} | |
<body {% block bodyAttributes %}{{ Utils.writeHtmlArguments(options) }}{% endblock %}> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment