Handlebars - 调用partial时的Concat字符串参数 [英] Handlebars - Concat string parameters when calling partial

查看:51
本文介绍了Handlebars - 调用partial时的Concat字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在使用Handlebars加载部分时是否可以使用另一个字符串连接变量。

I would like to know if it is possible to concat a variable with another string when loading a partial using Handlebars.

{{partial logos this ns=../ns nsr=../nsr id=id+"something"}}

我想连接 id +something并将其存储到 id 中,这将被发送到模板。

I'd like to concat id+"something" and storing it into id, which would be sent to the template.

我正在使用自定义助手来加载合并的部分(部分,车把提供 options.hash

I'm using a custom helper to load partials (partial) which merge this with the options.hash provided by handlebars.

推荐答案

实际上有一种方法。我已尝试使用默认的部分加载程序>,但我希望它也适用于部分。

There is a way actually. I've tried with default partial loader ">", but I hope it should work with "partial" too.

你可以写一个像这样的帮手

You can write a helper like this

Handlebars.registerHelper( 'concat', function(path) {
    return "/etc/path" + path;
});

并称之为

{{> responsive-image src=(concat '/img/item-tire.png') alt="logo" }}

我希望有所帮助。

这篇关于Handlebars - 调用partial时的Concat字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆