【问题标题】:Change an image src with the [src] binding? (Amp for Email)使用 [src] 绑定更改图像 src? (电子邮件放大器)
【发布时间】:2019-10-01 21:37:26
【问题描述】:

在 amp-bind Amp for Email 文档页面上,它显示了将 [src] 绑定到 amp-img 以更改图像源路径的示例(一个稍微复杂的示例):

<amp-state id="myAnimals">
  <script type="application/json">
    {
      "dog": {
        "imageUrl": "/img/dog.jpg",
        "style": "greenBackground"
      }
    }
  </script>
</amp-state>

<!-- Or change an image's src with the [src] binding. -->
<amp-img width="300" height="200" src="/img/dog.jpg"
    [src]="myAnimals[currentAnimal].imageUrl">
</amp-img>

但是,当我在 Playground 中验证时,我得到: 属性“[src]”可能不会出现在标记“AMP-IMG (AMP4EMAIL)”中。

我正在尝试对 Carousel 组件 (type="slides") 执行类似操作,当我单击下一张/上一张幻灯片时,我希望更改电子邮件中其他位置的副本/图像。虽然我可以更改副本,但我似乎无法为图像做同样的事情。

是否无法使用 Amp for Email 的 amp-bind 组件更改图像源路径?有解决办法吗?

【问题讨论】:

    标签: amp-html amp-email


    【解决方案1】:

    Vadim,您可以通过 amp-mustache 使用模板来修改 amp-img 的 src 属性。例如

    <amp-list ...>
    ...
     <template type="amp-mustache">
        <div class="products">
            <amp-img width="150"
                   height="100"
                   alt="{{name}}"
                   src="{{img}}"></amp-img>
            <p class="name">{{name}}</p>
            <p class="star">{{{stars}}}</p>
            <p class="price">{{price}}</p>
        </div>
    </template>
    

    ...

    我不记得为什么在 src 上绑定是不可能的,尽管安全似乎是可能的答案。所以不幸的是,如果您注意到模板仅在嵌套在 amp-form 或 amp-list 组件中时适用。如果有足够令人信服的用例允许在这些组件之外支持它,那么请随时创建功能请求,我们将非常乐意与您一起定义需求和实施更改。谢谢

    【讨论】:

    • 谢谢亚伦。我是 AMP 的新手。现在在我的 html 中,我有 1)Jason 脚本 2)amp-carousel 3)内容部分将更新。根据您的回复,我似乎需要包含 amp-list 组件,该组件将包含 json 脚本的 src 路径(而不是嵌入到 html 中)。我是否将下面的内容部分替换为 amp-list ?
      preview.amp.dev/static/inline-examples/images/image1.jpg" width="175" height="150" [src]="myState.adventure[currentAdventure].image">
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 2020-04-30
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多