Sky Blue Sofa Blog Modifying Block Templates for use with Thumbnail Generator for Concrete5 - Sky Blue Sofa Blog

Modifying Block Templates for use with Thumbnail Generator for Concrete5

Posted by Dave Rogers // October 2, 2015 // in Blog // 0 Comments

IMG_3217.JPG

Thumbnail Generator is an addon for concrete5 (v5.7+) that will go through the content of a page to find a suitable image that can be used as a thumbnail for the page.

While it works really slick, even importing and saving images to the file manager, there are some external images that are prohibited from being saved. Currently, these are Google properties: Google Maps and YouTube. So the Map and YouTube blocks are affected.

If you'd like to use Thumbnail Generator with these blocks, you may, but Thumbnail Generator will only store the URL to the image, not the image itself. In these instances you can change this type of code:

  1. <?php
  2. $thumbnail = $page->getAttribute('thumbnail');
  3. $img = Core::make('html/image', array($thumbnail));
  4. $tag = $img->getTag();
  5. $tag->addClass('img-responsive');
  6. print $tag;
  7. ?>

to look something like this:

  1. <?php
  2. $thumbnail = Concrete\Package\SkybluesofaThumbnailGenerator\Src\ThumbnailAttribute::createGeneratedThumbnailTag($page);
  3. $tag = $thumbnail->getTag();
  4. $tag->addClass('img-responsive');
  5. print $tag;
  6. ?>

The "ThumbnailAttribute" object does all the heavy lifting of creating the image tag.

Note that the image tag returned from a URL will not be responsive in the way that an image returned from a file would be.

You may also do it manually:

  1. <?php
  2. $generatedThumbnail = $page->getAttribute('generated_thumbnail');
  3. if ($generatedThumbnail) {
  4. $img = Core::make('html/image', array($generatedThumbnail));
  5. } else {
  6. $thumbnailUrl = $page->getAttribute('generated_thumbnail_url');
  7. $img = \HtmlObject\Image::create($thumbnailUrl);
  8. }
  9. $tag = $img->getTag();
  10. $tag->addClass('img-responsive');
  11. print $tag;
  12. ?>

About the Author

Dave Rogers

Dave is the founder of Sky Blue Sofa Web Design. He enjoys working out, spending time with his wife and dogs and programming. He grew up and currently resides in the Illinois Quad Cities. You can find his personal blog at strength/reliance.com.

View Profile »

Comments

You must be logged in to leave a reply. Login »