Loading Image Thumbnail
Permalink
I am loading a custom image attribute in a template. I like to load the attribute and assign a custom thumbnail ( Dashboard > System > Files> Thumbnails) to the image.
Now I have several way to load the image attribute. My Questions:
- How do I load the thumbnail (named: small).
- What is the best way to load the image attribute (see example: blogimage)
Now I have several way to load the image attribute. My Questions:
- How do I load the thumbnail (named: small).
- What is the best way to load the image attribute (see example: blogimage)
<?php if($c->getAttribute('blogimage')){ echo '<img src="' . $c->getAttribute('blogimage')->getVersion()->getRelativePath() . '"/>';} ?>
<?php $img = $c->getAttribute('blogimage'); ?> <?php if ($img): ?> <img src="<?php echo ($img->getVersion()->getRelativePath()); ?>"/> <?php endif; ?>
<img src="<?php $c = Page::getCurrentPage(); echo ($c->getAttribute('blogimage')->getVersion()->getRelativePath());?>">
Thank you for explaining.
Also asked the Question on Stack Overflow (https://stackoverflow.com/questions/51206234/loading-thumbnail-of-a-page-image-attribute-in-concrete5)
So now I am using
Also asked the Question on Stack Overflow (https://stackoverflow.com/questions/51206234/loading-thumbnail-of-a-page-image-attribute-in-concrete5)
So now I am using
$img = $c->getAttribute('blogimage'); if ($img !== null) { $imgVersion = $img->getVersion(); $thumbnailURL = $imgVersion->getThumbnailURL('small'); ?><img src="<?= $thumbnailURL ?>" /><?php }
Your second attempt is slightly better, because access the database only once ($img =...). Your third approach will raise an error if no image is set (getVersion() on null)
Working with thumbnails:
First get your Thumbnail Type:
Then you can get the blog image source url:
For more details, see the official documentation:https://documentation.concrete5.org/developers/working-with-files-an...