Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Last active September 19, 2018 14:30
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 cuonghuynh/9f4f8cab9f13358d1abac46bf0140df7 to your computer and use it in GitHub Desktop.
Save cuonghuynh/9f4f8cab9f13358d1abac46bf0140df7 to your computer and use it in GitHub Desktop.
Backend exports variables for Frontend

Template engine:

Usually, we place it in script section of footer.

<script type="application/json" data-from-backend>
    {
      "product_id": "{{ product.id }}",
      "user_address": "{{ userAddress }}"
    }
</script>

JS code:

const jsonObj = JSON.parse($('[data-from-backend]').html());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment