1
votes

As posted here https://www.concrete5.org/index.php?cID=751287 I want to get a thumbnail from a page using the 'old' way.

Before I could use the code below which included an image helper.

<div class="image-link">
    <a <?php if ($target != '') { ?> target="<?php echo $target ?>" <?php } ?> href="<?php echo $url ?>">
        <?php
        $ts = $page->getBlocks('Thumbnail Image');
        if (is_object($ts[0])) {
            $tsb = $ts[0]->getInstance();
            $thumb = $tsb->getFileObject();
            if ($thumb) {
                $ih->outputThumbnail($thumb, 170, 80, $title);
            }
        }
        ?>
    </a>
</div>

From this section of the subpage:

<div id="thumbnail">
    <?php
    if ($c->isEditMode()) {
        print '<br><br>';
        $a = new Area('Thumbnail Image');
        $a->display($c);
    }
    ?>
</div>

However now this has all changed and the new system uses page attributes for thumbnails. As the site is already setup the 'old' way I want to be able to retrieve the thumbnail the same way again.

Any help would be much appreciated.

2

2 Answers

1
votes

I have "thumbnail" page attribute set via the composer, and this is how I retrieve it in the page template:

 <?php
     $thumbnail = $c->getAttribute('thumbnail');
     if($thumbnail) {
         $img = Core::make('html/image', array($thumbnail));
         $tag = $img->getTag();
         print $tag;
     }
 ?>
1
votes

I dug out my experimentation hat and fixed it.

<div class="image-link">
                <a <?php if ($target != '') { ?> target="<?php echo $target ?>" <?php } ?> href="<?php echo $url ?>">
                    <?php
                    foreach ($blocks as $block) {
                        if ($block->getBlockTypeHandle() == "image" && $block->getAreaHandle() == "Thumbnail Image") {
                            if (is_object($block)) {
                                $tsb = $block->getInstance();
                                $thumb = $tsb->getFileObject();
                                if ($thumb) {
                                    $ih->outputThumbnail($thumb, 170, 80);
                                }
                            }
                        }
                    }
                    ?>
                </a>
            </div>