2016-03-02 19 views
1

这应该可能比现在更容易。我只想在HTML段落元素中放置一个链接。如何在HAML中的文本字符串中放置一个链接?

%p{class: "answer"}="Please upload your data to this portal in text (tab-separated) format. Download our template #{raw(link_to 'here', '/templates/upload_template.xlsx')} for sample data and a description of each column." 

Rails正在编码标签信息。我不希望标签被编码。我希望他们成为标签。

回答

2

您可以使用interpolation directly in Haml,做这似乎是解决这个问题在这种情况下。

所以不是这样:

%p= "Text with #{something_interpolated} in it." 

你可以做

%p Text with #{something_interpolated} in it. 

即你不需要=或引号,因为你只是添加一个字符串。您不应该也需要使用raw

(另外,请注意,你可以做%p.answer设置class属性,如果该值不被动态地设置时可以更清洁。)


为什么这是正在这里逃脱是不同的问题。我预计这两种情况(%p= "#{foo}"%p #{foo})的行为方式相同。然而,经过一些研究,这种行为似乎与Rails与Erb的行为方式相匹配。

3

您可以使用多条线路的任何块内,解决你的问题,我们将有这样的事情:

%p{class: "answer"} 
    Please upload your data to this portal in text (tab-separated) format. Download our template 
    = link_to 'here', '/templates/upload_template.xlsx' 
    for sample data and a description of each column." 
+0

虽然我们在这,但我们可以鼓励'p.answer'语法。比'%p {class:“answer”}'好得多 – froderik

相关问题