Skip to content

Instantly share code, notes, and snippets.

@peteheaney
Created April 30, 2020 15:35
Show Gist options
  • Save peteheaney/c7263cc67ebeaf7b7bea24303a49a3cb to your computer and use it in GitHub Desktop.
Save peteheaney/c7263cc67ebeaf7b7bea24303a49a3cb to your computer and use it in GitHub Desktop.
Twig - use the value of a variable as a hash key
{% 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