【问题标题】:Using headless pages in section lists in hugo在 hugo 的部分列表中使用无头页面
【发布时间】:2018-11-12 21:00:07
【问题描述】:

我需要构建一个由一些静态页眉材料、静态页脚材料和几个用户管理内容部分组成的部分页面。此用户管理的内容是零碎的,因此不应有固定链接。

我认为使用headless pages 是一个好方法。

看起来是这样,这些片段必须有一个带有index.md 的目录,并且应该可以使用.Site.GetPage 运算符访问。

我正在努力弄清楚如何使用.Site.GetPage 来获取要迭代的页面列表。将有 2..n 个用户部分,如果内容模块的数量发生变化,我不想重建该部分的模板。

我假设使用.Site.GetPage 查询多个页面有一些魔力,或者有一个完全不同的运算符。

那个,或者我完全误解了如何使用无头页面。

这是我的部分模板 (../layouts/the-range/section.html):

{{ define "main" }}
    <div id="page-wrapper">
        <div class="halfhero" id="map"></div>
    </div>

    {{ $sections := .Site.GetPage "/the-range/*" }}
    <!-- leaf content at .../content/the-range/*/*.md -->
    {{ range $sections }}
    <section class="range-section">
        <div class="section-content">
            {{.Content}}
        </div>
        <img src="{{.Site.BaseURL}}{{.Params.images}}">
    </section>

    {{ end }}
{{ end }} 

无头内容只是作为叶子包的一系列降价文件。

【问题讨论】:

    标签: hugo


    【解决方案1】:

    通过 Hugo 社区https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2

    给定这样的结构:

    content/headless/
    ├── index.md     # headless = true in front matter
    ├── five.md
    ├── four
    │   └── index.md
    ├── one
    │   └── index.md
    ├── three
    │   └── index.md
    └── two
        └── index.md
    

    你可以这样做:

    {{ $headlessbundle := .Site.GetPage "/headless" }}
    {{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
      {{.}}
    {{ end }}
    

    应该输出:

    Page(/headless/five.md) 
    Page(/headless/four/index.md) 
    Page(/headless/three/index.md) 
    Page(/headless/two/index.md) 
    Page(/headless/one/index.md)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      • 2019-05-19
      • 1970-01-01
      相关资源
      最近更新 更多