簡體   English   中英

如何在自定義部分中將 alt 添加到圖像

[英]How to add alt to image in custom section

我創建了一個自定義部分,我在其中添加了一張圖片。 我需要顯示它的替代品。 我怎樣才能做到這一點?

 <img src="{{ section.settings.img_section_image | img_url: '960x645'}}"> {% schema %} { "name": "Img section", "settings": [ { "id": "img_section_image", "type": "image_picker", "label": "Add image" }, ], "presets": [ { "name": "Img sections" } ] } {% endschema %}

上傳圖片后,只需單擊圖片,彈出窗口中就會出現一個彈出窗口,其中有一個文本字段可以為該圖片添加 alt 標簽。

它看起來像這樣的圖像: 在此處輸入圖像描述

要在 img 標簽上獲取它,您可以使用默認的image_tag

{{ section.settings.img_section_image | image_url: width: 200 | image_tag }}

它會在創建 img 標簽或使用

{{ section.settings.img_section_image| image_url: width: 200 | image_tag: alt: 'My image's alt text' }}

無需后端即可手動添加自定義標簽。

如果你不使用image_tag ,那么試試這樣的

<img src="{{ section.settings.img_section_image | img_url: '960x645'}}" alt="{{section.settings.img_section_image.alt}}">

我希望這對您和其他人也有幫助


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM