在咖啡HAML谐音(.hamlc) [英] Partials in Coffee HAML (.hamlc)
问题描述
我使用Backbone.js的上轨后端是 HAML咖啡 ,这是由 haml_coffee_assets 编译。有一个在我的模板一些重复。
有没有一种方法来创建铁轨般的谐音干我的模板?
增加:我可以做 content_for(:东西)?
在咖啡HAML
有在Haml的咖啡没有 content_for
帮手,但你根本就呈现模板中的其他模板。
无局部变量
例如,你已经模板测试
:
%对我的偏
UL%
%Li是包括
您可以像这样另一个模板中包含它
%对另一个模板
!= JST ['测试'()
%P这包括部分
诀窍是用来反转义呈现的HTML!=
。
使用局部变量
要通过局部变量,只是将它们发送到 JST
功能。如果这是您的局部(文章/ _comments.jst.hamlc
)
%H2 = @称号
%,P = @内容
那么这可能是的模板
本文%H1评论
- 在@ article.comments评论
!= JST ['文章/ _comment(评论)
I am using backbone.js on a rails backend with HAML Coffee, which is compiled by haml_coffee_assets. There is some duplication in my templates.
Is there a way to create rails-like partials to dry up my templates?
Addition: Can I do content_for(:something)
in Coffee HAML?
There is no content_for
helper in Haml Coffee, but you simply can render another template within a template.
Without Local Variables
For example, you've a template test
:
%p My Partial
%ul
%li Is included
You can include it within another template like this:
%p Another template
!= JST['test']()
%p That includes a partial
The trick is to unescape the rendered HTML with !=
.
With Local Variables
To pass local variables, just send them to the JST
function. If this is your partial (articles/_comments.jst.hamlc
):
%h2=@title
%p=@content
Then this may be your template:
%h1 Comments for this article
- for comment in @article.comments
!= JST['articles/_comment'](comment)
这篇关于在咖啡HAML谐音(.hamlc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!