Skip to content

Instantly share code, notes, and snippets.

@riccardolardi
Created April 1, 2020 13:22
Show Gist options
  • Save riccardolardi/b5fbb07ebf87c4e0c0515b61af3bd3bd to your computer and use it in GitHub Desktop.
Save riccardolardi/b5fbb07ebf87c4e0c0515b61af3bd3bd to your computer and use it in GitHub Desktop.
elementapi
<?php
use craft\elements\Entry;
use craft\helpers\UrlHelper;
return [
'endpoints' => [
'acts.json' => function() {
return [
'pretty' => true,
'paginate' => false,
'elementType' => Entry::class,
'criteria' => ['section' => 'acts'],
'transformer' => function(Entry $entry) {
$images = [];
foreach ($entry->actImages->all() as $image) {
$images[] = $image;
}
return [
'title' => $entry->title,
'description' => $entry->actDescription,
'link' => $entry->actLink,
'images' => $images
];
}
];
}
]
];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment