如何在中间人的局部中渲染局部 [英] How to rendering partials within a partials in middleman

查看:78
本文介绍了如何在中间人的局部中渲染局部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Haml局部,其中许多包含样板

I have some Haml partials, many of which contain the boilerplate

.container .row .col-lg-12

.container .row .col-lg-12

当我尝试抽象出ala = partial "site_section"时,我得到:

When I try to abstract that out ala = partial "site_section", I get:

syntax error, unexpected keyword_end, expecting end-of-input end;end;end;end

我正在使用ruby 2.2.2.

I'm using ruby 2.2.2.

如何在Middleman的Haml部分中渲染Haml部分?

How do I render a Haml partial within a Haml partial in Middleman?

谢谢

更新 这显然是处理我的部分(以上)问题的一种特殊情况.我还有其他的partials-in-partials渲染很好.

update This is apparently some kind of special case dealing with my partial (above). I have other partials-within-partials rendering just fine.

更新 关于此此存储库,布局实际上是:

update With respect to this this repo, the layout would actually be:

_site_section:

_site_section:

.container .row .col-lg-12

.container .row .col-lg-12

_nested_section:

_nested_section:

= partial "site_section"
  MOAR (nested) HAML

index.haml:

index.haml:

=partial "nested_section"

推荐答案

由于HAML的工作方式,以下内容无效:

Because of the way HAML works the following is invalid:

= partial "site_section"
  MOAR (nested) HAML

如果您想添加更多文本或HAML,则可以通过例如将文本置于上一行的同一级别来实现.

If you want to add more text or HAML then you can achieve it for example by putting the text at the same level of the previous line

= partial "site_section"
MOAR (nested) HAML

或将其嵌套在div中:

Or nesting it within a div:

= partial "site_section"
.more   
  MOAR (nested) HAML

因此,如果您要执行的操作是将额外的HAML嵌套到 site_section 部分的输出中,则必须将嵌套的额外HAML放在嵌套的部分中:

So If what you are trying to do is to nest extra HAML to the output of the site_section partial, then you have to put the nested extra HAML in the nested partial:

.container
  .row
    .col-lg-12
      = partial 'nested_stuff'
= partial 'nested_stuff'

希望这会有所帮助,我用工作示例更新了存储库.

Hope this helps, I updated the repo with the working example.

这篇关于如何在中间人的局部中渲染局部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆