【问题标题】:What would be the correct syntax to add the 'alt' attribute in Shopify?在 Shopify 中添加“alt”属性的正确语法是什么?
【发布时间】:2019-09-11 03:12:20
【问题描述】:

我正在尝试将alt 文本添加到我的图像中,但是,由于语法,我有点困惑。基本上,每个网站都说要做

img src=logo.png alt="Something.com | The best something ever"

但是,因为我是在 Shopify 上构建的,所以我的代码如下所示:

img src="{{ '3Y9C5514.jpg' | asset_url }}"

我是菜鸟,所以括号和"| asset_url" 让我很困惑。我应该在哪里添加alt="my alt text"

【问题讨论】:

  • 我从未亲自使用过 Shopify,但我怀疑这会阻止使用 alt 属性正常应用的 alt 文本。

标签: html shopify alt


【解决方案1】:

以下是您将 alt 文本与图像 URL 一起放置的方式。

<img src="{{ '3Y9C5514.jpg' | asset_url }}" alt="Alt text goes here"/>

"|asset_url" 返回主题“assets”文件夹中文件的 URL。因此,如果您的图像文件存在于文件夹中,它将获取图像 url。

#Input
{{ '3Y9C5514.jpg' | asset_url }}

#Output
//cdn.shopify.com/s/files/1/0087/0462/t/394/assets/3Y9C5514.jpg?28253

但是,如果您要插入图片,我的建议是使用 - "|asset_img_url"。这将返回主题的“资产”文件夹中图像的资产 URL。 asset_img_url 接受图片尺寸参数。

#Input
{{ 'logo.png' | asset_img_url: '300x' }}

#Output
//cdn.shopify.com/s/files/1/0000/0001/t/1/assets/logo_300x.png?42

来源:URL Filters

【讨论】:

    猜你喜欢
    • 2020-01-23
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 2016-06-28
    • 2021-04-06
    • 1970-01-01
    相关资源
    最近更新 更多