Skip to content

Instantly share code, notes, and snippets.

@nfourtythree
Last active August 29, 2015 14:01
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 nfourtythree/96c4ee61b287d48fc10f to your computer and use it in GitHub Desktop.
Save nfourtythree/96c4ee61b287d48fc10f to your computer and use it in GitHub Desktop.
Craft json plugin
// Template Tag
{{ entries | examplePlugin(
"id",
"title",
"category.title",
"myRelatedField.title",
"myRelatedField.customField",
"myRelatedField.itsRelatedField.title") | raw }}
// Returns
{
{
"id": 1,
"title": "Entry Title",
"category": [
{
"title": "Category Title"
}
],
"myRelatedField": [
{
"title": "Related Entry's Title",
"customField": "Custom Data",
"itsRelatedField": [
{
"title": "Related Related Title"
}
],
}
]
},
{
"id": 2,
"title": "Entry Title 2",
"category": [
{
"title": "Category Title 2"
}
],
"myRelatedField": [
{
"title": "Related Entry's Title 2",
"customField": "Custom Data 2",
"itsRelatedField": [
{
"title": "Related Related Title 2"
}
],
}
]
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment