2016-12-07 32 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}} 
相關問題