Closed Tapefabrik closed 8 years ago
This is a commonly discussed topic that may seem like a bug at first but really isn't. The Toolkit has no idea what type of field was used to enter content in a page. It doesn't even know if it was added via the panel or via any other means. There is no information in the content file that indicates what is an image and what is text. To that effect, it is the developer's responsibility to transform what is merely the name of a file into a media element so the url() function can be used.
Thanks for the valuable feedback! Anyway i find it weird to not even get the message that this is not a valid media / file object for the function, isn't it?
Well the url function is used to construct a url but to verify that a page or asset exists at that url. This the the intended behavior of the URL function I believe.
If you try to use image() on the other hand, it will return an error if what you're passing to the function is not an image in the context of the function.
Thanks for the feedback!
You can also use this:
$image = $page->myimagefield()->toFile();
if($image) {
// image exists
echo $image->url();
}
Please note that this is not part of the Toolkit but of Kirby CMS.
When using a panel field of the type "image" i would expect the field function "url()" to return the absolute path of the image, like stated in the Documentation.
But instead of returning
http://www.example.com/kirby-folder/content/page/image.jpg
the function returns
http://www.example.com/kirby-folder/image.jpg
surely, you can use a workaround by using the field function image() and use the field value as parameter, but shouldn't url() behave like mentioned above anyway?