【问题标题】:Use nested layouts in Middleman在 Middleman 中使用嵌套布局
【发布时间】:2012-04-13 09:48:59
【问题描述】:

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

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

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

目前我完全没有意识到我应该从哪里开始。我了解如何将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

【问题讨论】:

    标签: ruby haml middleman


    【解决方案1】:

    在 3.0 中,index 使用 inner 布局,这将是 wrap_layout layout

    在 2.0 中,您需要组合使用部分和 content_for 块。

    【讨论】:

    • 我已经在使用 content_for 和 yield_content。当说partials时,你的意思是我应该把所有common_inner_styles、common_inner_scripts和common_inner_markup放到单独的partials中?我会很好,但是可以将内容放在部分内容中吗?我的意思是我想要所有内页自定义内容的一些通用包装元素
    【解决方案2】:

    乍一看,我很想用两个模板来做这件事。也许没有那么优雅或干燥,但肯定是可以理解的并且以后容易调整。例如。对于我们的网站,我们有一个front page layout 和一个rest of the site layout。然后在每个 MiddleMan 源文件中声明将使用哪种布局 (see example)。

    除此之外,我希望能从对你的情况有魔力的 HAML 大师那里学到一些东西!

    【讨论】:

    • 是的,绝对不干。我真正拥有的——全站点模板(不是那么小),然后是每个内页的一些更常见的标记。所以我绝对不会在这里重复任何内容
    猜你喜欢
    • 1970-01-01
    • 2013-06-17
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多