Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
Last active December 21, 2015 02:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonkelly/6234999 to your computer and use it in GitHub Desktop.
Save brandonkelly/6234999 to your computer and use it in GitHub Desktop.
Turn a list of entries into JSON in Craft
{
entries: [
{% for entry in craft.entries.find() %}
{
title: "{{ entry.title | e('js') }}",
tags: [
{% for tag in entry.myTagsField %}
"{{ tag.name | e('js') }}" {% if not loop.last %},{% endif %}
{% endfor %}
],
assets: [
{% for asset in entry.myAssetsField %}
"{{ asset.url | e('js') }}" {% if not loop.last %},{% endif %}
{% endfor %}
]
} {% if not loop.last %},{% endif %}
{% endfor %}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment