-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Usage with Element API #1
Comments
Not forgotten this, just been super busy. I'll try to find time to add an example next week. |
Sorry for delay! Here's an example of using Imgixer with the Element API, assuming your image field is named 'image'. Basically, pass the image path as the first argument to the function, and an array of Imgix parameters as the second argument. <?php
use craft\elements\Entry;
use craft\helpers\UrlHelper;
use croxton\imgixer\twigextensions\ImgixerTwigExtension;
return [
'endpoints' => [
'news.json' => function() {
return [
'elementType' => Entry::class,
'criteria' => ['section' => 'news'],
'transformer' => function(Entry $entry) {
$asset = $entry->image->one();
return [
'title' => $entry->title,
'url' => $entry->url,
'jsonUrl' => UrlHelper::url("news/{$entry->id}.json"),
'summary' => $entry->summary,
'image' => (new ImgixerTwigExtension)->imgix($asset->path, array(
'ar' => '16:9',
'w' => 2000,
'signed' => true
))
];
},
];
}
]
]; |
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey.
Could you please show an example of how to use your plugin with the Element API plugin?
Thanks
The text was updated successfully, but these errors were encountered: