gpt4 book ai didi

ruby - 在 Middleman 中使用嵌套布局

转载 作者:太空宇宙 更新时间:2023-11-03 18:26:39 34 4
gpt4 key购买 nike

我基本上使用 Middleman 2,但如果这只能在 Middleman 3 中完成,我可以切换到它

我有 layout.haml,其中包含所有样板文件,同时也是索引的布局。

现在我想要 inner.haml 布局,它将适用于其余页面,继承 layout.haml(在术语,我不会重复样板部分),将包括一些额外的通用样式/脚本、一些通用标记,然后将重新放置 yield block 。

目前我完全没有意识到我应该从哪里开始。我了解如何将 inner.haml 设置为默认布局并将 layout.haml 设置为“/”路线的布局,但系统如何知道 inner.haml 实际上嵌套在 layout.haml 中?

示例设置

layout.haml

!!!5
%html
%head
%script(src="HTML5 shiv")
%title
My Site
\|
= yield_content :title
= stylesheet_link_tag "site.css"
= yield_content :page_styles
%body
%div(role="main")
= yield_content :content
%script(src="jquery")
= yield_content :page_scripts

index.html.haml

- content_for :title do
Index
- content_for :page_styles do
= stylesheet_link_tag "index.css"
- content_for :page_scripts do
%script(src="index.js")
- content_for :content do
Cool banner here

inner.haml

-# somehow inherits from / extends layout.haml
- content_for :page_styles do
-# somehow I'm putting some common content and then reinclude the block from the specific page
= stylesheet_link_tag "inner.css"
= yield_content :page_styles
-# same thing for page_scripts
- content_fir :content do
-# again I define some common HTML, then include page's content

最佳答案

在 3.0 中,您可以让 index 使用 inner 布局,这将是 wrap_layout layout

在 2.0 中,您需要结合使用 partials 和 content_for block 。

关于ruby - 在 Middleman 中使用嵌套布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9930614/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com