【问题标题】:Loading Thumbnail of a page Image Attribute in Concrete5在 Concrete5 中加载页面图像属性的缩略图
【发布时间】:2018-12-14 19:36:41
【问题描述】:

我喜欢加载一个图像属性并为图像分配一个名为small(在Dashboard > System > Files> Thumbnails 中创建)的自定义缩略图。

我在模板中创建了一个自定义图像属性blogimage。加载图像属性有效。只需要知道如何加载自定义缩略图。

<?php
    $img = $c->getAttribute('blogimage'); ?>
    <?php if ($img): ?>
    <img src="<?php  echo ($img->getVersion()->getRelativePath()); ?>"/>
<?php endif; ?

【问题讨论】:

    标签: php image attributes thumbnails concrete5


    【解决方案1】:

    如果blogimage是一个Image/File属性的句柄,而$c是一个Page实例,下面的代码

    $img = $c->getAttribute('blogimage');
    

    如果页面没有该属性的值,则返回 null,否则返回 Concrete\Core\Entity\File\File 实例。

    然后

    $imgVersion = $img->getVersion();
    

    返回一个Concrete\Core\Entity\File\Version 实例,该实例具有getThumbnailURL 方法。

    因此,为了获得带有句柄 small 的缩略图类型的 URL,您只需编写以下代码:

    $img = $c->getAttribute('blogimage');
    if ($img !== null) {
        $imgVersion = $img->getVersion();
        $thumbnailURL = $imgVersion->getThumbnailURL('small');
        ?><img src="<?= $thumbnailURL ?>" /><?php
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-29
      • 2016-03-01
      • 2014-03-17
      • 2021-11-10
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多