1

I need to pass an entire Craft object into a JavaScript function. I followed the instructions in this post, however this only covers passing in a string.

{% includeJsFile "/js/homepage.js" %}
{% set myJs %}
   playlistData('{{myObject}}');
{% endset %}   
{% includeJs myJs %}

Any ideas?

4

You have to break it up into individual values before you can pass it through to JS...

{% includeJsFile "/js/homepage.js" %}
{% set myJs %}
   playlistData({
      field1: '{{ myObject.field1 }}',
      field2: '{{ myObject.field2 }}',
      field3: '{{ myObject.field3 }}'
   });
{% endset %}   
{% includeJs myJs %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.