[英]How to include an ember js helper function inside a handlebars expression
I want to include a helper myHelper
inside a link-to
expression like below but it seems you cannot have an expression directly inside another expression. 我想在一个类似于下面的link-to
表达式中包含一个帮助器myHelper
但是似乎您不能在另一个表达式中直接包含一个表达式。
{{# link-to "someUrl" class="txt-dark-1 {{myHelper data}}"}} Some text {{/link-to}}
How could you include a helper function in this instance? 您如何在此实例中包括一个辅助函数?
If you want to use the value of your helper directly, you can call your helper via ()
instead of {}
like this: 如果您想直接使用助手的值,可以通过()
而不是{}
来调用助手,如下所示:
{{# link-to "someUrl" class="txt-dark-1" (myHelper data) }}
Some text
{{/link-to}}
If you want to concat another string value to your class attribute, you can use it via concat
helper like this: 如果您想将另一个字符串值连接到您的class属性,则可以通过concat
帮助器使用它,如下所示:
{{# link-to "someUrl" class=(concat "txt-dark-1 " (myHelper data)) }}
Some text
{{/link-to}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.