Partials in Coffee HAML (.hamlc)

馋奶兔 提交于 2019-12-03 05:51:20
Netzpirat

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!