0

我有这个 html x 车把代码:

                    {{#each product.custom_fields}}
                      {{#if name '===' 'hero_image_name'}}
                        <source media="(min-width: 800px)"
                            srcset="{{cdn "webdav:product_images/{{{value}}}"}}"
                      {{/if}}
                    {{/each}}>

问题是,我无法在 srcset 中呈现“{{{value}}}”。它只是从字面上输出“{{{value}}}”。

我试着用反斜杠转义它,像这样的脚本:

        Handlebars.registerHelper('escape', function(variable) {
        return variable.replace(/(['"])/g, '\\$1');
    });

然后添加:

{{{escape value}}}

但似乎没有任何效果。我找不到像这样的任何具体案例,有人知道如何输出这个吗?

4

1 回答 1

0

你需要像这样使用它

 {{#each product.custom_fields}}
                      {{#if name '===' 'hero_image_name'}}
                        <source media="(min-width: 800px)"
                             // with double braces not triple {{value}}
                            srcset="{{cdn "webdav:product_images/{{value}}"}}"
                      {{/if}}
                    {{/each}}>

参考:https ://handlebarsjs.com/guide/expressions.html

于 2020-04-20T21:00:43.963 回答