Skip to content

Instantly share code, notes, and snippets.

@piotrpog
Created October 13, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotrpog/1fbf8111dd880c3ff962e7b8fab96938 to your computer and use it in GitHub Desktop.
Save piotrpog/1fbf8111dd880c3ff962e7b8fab96938 to your computer and use it in GitHub Desktop.
Twig macro for passing Twig variables into Javascript. More info: http://craftsnippets.com/articles/using-javascript-in-twig-templates-with-craft-cms
{% macro jsVar(variable, jsVariableName) %}
{# v1 #}
var {{jsVariableName}} = {{variable|json_encode|raw}};
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment