2016-12-07 63 views
0

我有一个非常简单的表单域组件,它显示带有标签的输入。 部件/表单域,input.hbsEmber JS将一个值传递给包含HTML的组件属性

<label>{{label}}</label> 
{{input value=value type=type }} 

template.hbs

{{form-field-input label="Which of our products do you like the most?" type='Text' value=favouriteProduct}} 

说我想这个词产品在标签在我的应用程序链接到另一条路线,其中列出了所有的产品。有什么办法可以做到这一点?

我知道下面的工作不能正常工作,因为角色只会被转义。是否有某种方式可以在父模板的JS文件中构建标签并传入?

{{form-field-input label="Which of our {{#link-to 'products'}}products{{/link-to}} do you like the most?" type='Text' value=favouriteProduct}} 
+0

为什么选择snippet?当它不被使用 – Mahi

+0

您是否考虑使用上下文组件而不是将html作为属性?我更喜欢通过上下文组件提供html内容,而不是您解释的方式。如果上下文组件是一个选项,我可以提供帮助。 – alptugd

+0

您可以像'label-pre','label-link','label-post','forwardRouteName'那样发送您的'label'属性,然后根据需要将它们组合到您的组件中。 – AcidBurn

回答

0

您可以考虑安装ember-cli-showdown

ember install ember-cli-showdown 

我你component.hbs文件

<label>{{markdown-to-html label}}</label> 
{{input value=value type=type }} 

当使用组件,你可以直接把你的普通的HTML,并会得到corectly渲染。

{{form-field-input label="Which of our <a href='/products'>products</a> do you like the most?" type='Text' value=favouriteProduct }} 

我希望这能帮上忙。

0

使用组件块,我们可以解决上述问题。

// hbs 
{{#if hasBlock}} 
    <label>{{yield}}</label> 
{{else}} 
    <label>{{label}}</label> 
{{/if}} 
{{input value=value type=type }} 

// using in template -- if need custom markup 
{{#form-field-input type='Text' value=favouriteProduct}} 
    {{#link-to 'products'}}products{{/link-to}} 
{{/form-field-input}} label="Which of our products do you like the most?" 

// using in template -- if custom markup not needed 
{{form-field-input label="Which of our products do you like the most?" type='Text' value=favouriteProduct}} 
相关问题