英文:
Generate thumbnail image on plugin
问题
如何为自定义插件中的此部分生成缩略图图像?
{% for element in category.img.elements %}
   {% if element.media.url %}
      <img src="{{ element.media.url }}" class="product-image is-standard">
   {% endif %} 
{% endfor %}
在这段代码中,它只显示主图像,我想为该图像生成缩略图。
英文:
how can I generate the thumbnail image for this section on the custom plugin?
{% for element in category.img.elements %}
   {% if element.media.url %}
      <img src="{{ element.media.url }}" class="product-image is-standard">
   {% endif %} 
{% endfor %}
on this code it's only showing main image, I want to generate the thumbnail for that image
答案1
得分: 1
{% for element in category.img.elements %}
    {% sw_thumbnails 'category-img-thumbnails' with {
        media: element.media,
        sizes: {
            'default': '200px'
        },
        attributes: {
            'class': 'some-class',
            'alt': 'alternative',
            'title': 'title'
        }
    } %}
{% endfor %}
英文:
Use the sw_thumbnails helper.
{% for element in category.img.elements %}
    {% sw_thumbnails 'category-img-thumbnails' with {
        media: element.media,
        sizes: {
            'default': '200px'
        },
        attributes: {
            'class': 'some-class',
            'alt': 'alternative',
            'title': 'title'
        }
    } %}
{% endfor %}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论