I'm trying to integrate the ElementAPI plugin into my site. Essentially, I need to output all of the assets within the website into a JSON file that I can link to in the load manifest of PreloadJS. If you read the docs here, you'll see that the images can be loaded from an external JSON file.
Here's what I've been working with so far:
<?php
namespace Craft;
return [
'endpoints' => [
'assets.json' => [
'elementType' => 'Entry',
'criteria' => ['section' => 'news'],
'transformer' => function (EntryModel $entry) {
$images = [];
foreach ($entry->featuredImage as $image) {
$images[] = $image->url;
}
return [
'image' => $entry->image
'jsonUrl' => UrlHelper::getUrl("assets/data.json")
];
},
]
]
];
So, to sum up, what I'm needing to do is build an API that will get a list of all the assets used in my site and output them into a JSON file that I can link to in a JS file as part of the PreloarJs plugin. This would make my preloader dynamic and allow me to keep my javascript external, rather than getting the assets inline, which I have been doing.
Thanks!
craft/config/elementapi.php
file? Are you trying to output every asset on the site or just every asset that is in use? – Brad Bell Jul 11 '16 at 5:01