使用中间人,如何将一个 HAML 文件包含在另一个 HAML 文件中?
我正在使用中间人进行一些快速原型设计,但我一生都无法弄清楚如何将一个 HAML 文件包含到另一个 HAML 文件中。
我可以在布局文件中包含内容,但无法让一个非布局文件包含另一个非布局文件。我想在某些页面上重用一些 HTML 块,我想我可以做到这一点。我已经尝试过:
- render: partial=>"shared/nav.haml"
=shared/nav.html
="shared/nav.html
但这些都不起作用。
我是否缺少配置选项或插件?这是一个全新的中间人安装。
答案
部分可能需要以下划线开头的文件名。我的部分内容放置在名为共享的文件夹中。文件的全名是 _nav.html.haml
这对我有用。
!= haml :"shared/_nav"
上下文示例:
#email.main.subscriber.resize
#bg-wrap
%div
%img{:src=>"images/backgrounds/image.png",:alt=>""}
%section#zone10
!= haml :"shared/_nav"
您还可以使用下面批准的答案中指定的格式。
I'm using middleman to do some rapid prototyping and can't for the life of me figure out how to include one HAML file into another HAML file.
I can include stuff in a layout file, but can't get one non-layout file to include another non-layout file. There are blocks of HTML that I want to reuse on some pages and I think I could do this. I've tried:
- render: partial=>"shared/nav.haml"
=shared/nav.html
="shared/nav.html
and none of these work.
Am I missing a config option or plugin? This is a fresh middleman install.
ANSWER
Partials may need file names that start with an underscore. My partial is placed in a folder called shared. The full name of the file is _nav.html.haml
This worked for me.
!= haml :"shared/_nav"
Example in context:
#email.main.subscriber.resize
#bg-wrap
%div
%img{:src=>"images/backgrounds/image.png",:alt=>""}
%section#zone10
!= haml :"shared/_nav"
You may also use the format specified in the approved answer below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一直在 MiddleMan 中使用 HAML,并且非常高兴。以下是对我有用的内容:
我有一个文件:
source/_donate_buttons.h
这使用显示的部分语句来包含名为
source/_paypal_donate_button.html.haml
的文件。我将
_donate_buttons.html.haml
文件本身包含在几个地方:虽然我认为这也可能是:
即我认为
partial
是你的魔力寻找。而且,为了完整起见,这里有一个稍微精简的
_paypal_donate_button.haml
,它显示了参数化如何在那里工作:Fwiw,我认为该文件不需要是
_filename.html.haml
也可以是_filename.haml
。另外,我正在本地化这些,因此忽略 t('tagname') 并将字符串放在那里。 (我不想在复制粘贴示例时引入错误,因此我将它们留在那里。)希望这会有所帮助!
I've been using HAML with MiddleMan and couldn't be happier. Here is what is working for me:
I have a file:
source/_donate_buttons.h
This uses the partial statement shown to include a file called
source/_paypal_donate_button.html.haml
.And I include the
_donate_buttons.html.haml
file itself in a couple of places with:though I think this could also be:
I.e. I think
partial
is the magic you're looking for.And, just for completeness, here is a slightly stripped down
_paypal_donate_button.haml
which shows how the paramaterization works there:Fwiw, I don't think the file needs to be
_filename.html.haml
and can instead be_filename.haml
. Also, I'm localizing these, so ignore the t('tagname') and just put strings there. (I didn't want to introduce an error copy-pasting the examples so I left them in there.)Hope this helps!