Hi there,
I would like to create Volt function, which will return URI to the picture.
It will be called like that:
{{ get_image_url(_post.image, "640x291") }}
In this example I have _post, which is database object (an array in fact) and desired image resolution.
My function should return something like that: https://img.website.com/api/image/ad0733dc-1042-59ab-d5c1-dccfc23fe997/size/640x291
String ad0733dc-1042-59ab-d5c1-dccfc23fe997 is stored in the database under image property of the post.
What is difficult to me is that my Volt function looks like that:
$compiler->addFunction(
'get_image_url',
function ($resolvedArgs, $exprArgs) use ($compiler, $config)
{
$filename = $compiler->expression($exprArgs[0]['expr']);
$resolution = $compiler->expression($exprArgs[1]['expr']);
// e.g. https://img.website.com/api/image/ad0733dc-1042-59ab-d5c1-dccfc23fe997/size/640x291
return sprintf(
'%s%s/api/image/%s/size/%s',
$config->app->imagesProviderUrl,
$config->app->imagesProviderBaseUri,
$filename,
$resolution
);
}
);
But as $filename I am getting something like:
$_post->image
not the value of the post property.
Yesterday I was getting following error regarding the filename: Array to string conversion for a similar code to the above.
Your help will be very welcome!
Today in error.log I am getting:
ParseError: syntax error, unexpected ':', expecting ',' or ';' in \/data\/projects\/web\/phalcon\/rabbitmq\/storage\/cache\/volt\/_data_projects_web_phalcon_website_app_views_partials_blog-item.volt.php
becasue PHP code looks as follow:
<img src="<?= https://img.website.com/api/image/$_post->image/size/'640x291' ?>" alt="Ipsum" >