Responsive Page Attribute Image
Permalink
Hi, I have searched but not found an answer.
I have created a page Image/File attribute which is uses an image. Is there a way to output the image using the responsive thumbnails?
I have successfully coded in the output of the attribute directly in a theme Page Type.
<?php
$img = $c->getAttribute(‘attributename’);
if($img) {?>
<img src="<?php echo ($img->getVersion()->getRelativePath());?>">
<?php }
?>
However, currently it only outputs as one image size and doesn’t use the scaleable thumbnails available .
Is it possible to make the image attribute use the responsive thumbnails?
I have created a page Image/File attribute which is uses an image. Is there a way to output the image using the responsive thumbnails?
I have successfully coded in the output of the attribute directly in a theme Page Type.
<?php
$img = $c->getAttribute(‘attributename’);
if($img) {?>
<img src="<?php echo ($img->getVersion()->getRelativePath());?>">
<?php }
?>
However, currently it only outputs as one image size and doesn’t use the scaleable thumbnails available .
Is it possible to make the image attribute use the responsive thumbnails?
Hi,
thank you for your reply. I have read this before but hadn't associated this to the file/image page attribute. I found responsive thumbnails work OK for the image block and content block. I will re-read it again to see if makes things any clearer.
Regards
Luke
thank you for your reply. I have read this before but hadn't associated this to the file/image page attribute. I found responsive thumbnails work OK for the image block and content block. I will re-read it again to see if makes things any clearer.
Regards
Luke
Yes but in your code, you are already grabbing the image object.
On that page, it says to do this:
And the variable $file is the file (or image) object.
In your code, you did
so your $img is also an image object.
So if I'm not mistaken, if you do:
it should do what you want.
Just remember that if you didn't do the mapping in your page_theme file, it will simply output a normal img tag.
Hope this helps
On that page, it says to do this:
// $file, our file object. $image = \Core::make('html/image', array($file)); $tag = $image->getTag();
And the variable $file is the file (or image) object.
In your code, you did
$img = $c->getAttribute('attributename');
so your $img is also an image object.
So if I'm not mistaken, if you do:
// $file, our file object. $file = $c->getAttribute('attributename'); $image = \Core::make('html/image', array($file)); $tag = $image->getTag();
it should do what you want.
Just remember that if you didn't do the mapping in your page_theme file, it will simply output a normal img tag.
Hope this helps
you need to map screen widths to thumbnail types in your theme page_theme file. Then using Concrete5 core function you can automatically output the appropriate responsive picture tag.
it's all explained here:https://documentation.concrete5.org/developers/designing-for-concret...
Hope this helps