Created
April 30, 2020 15:35
-
-
Save peteheaney/c7263cc67ebeaf7b7bea24303a49a3cb to your computer and use it in GitHub Desktop.
Twig - use the value of a variable as a hash key
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 foo = "myKey" %} | |
{% set bar = "my value" %} | |
{# To name a hash key with the value of the foo variable, wrap the variable in parentheses: #} | |
{% set newThing = {(foo): bar} %} | |
{# Which is the same as #} | |
{% set newThing = {myKey: "my value"} %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment