首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hugo不会呈现单页布局,而是使用_default单页布局

hugo不会呈现单页布局,而是使用_default单页布局
EN

Stack Overflow用户
提问于 2019-10-04 13:29:29
回答 2查看 2.3K关注 0票数 1

)

我正试图为hugo.io创建自己的主题。到目前为止一切都很好。我唯一的问题是,我不能让hugo呈现单个部分内容的自定义布局。

对于帖子,这是很好的:

  • 正确调用index.html
  • 正确调用“布局/帖子”中的single.html
  • 对于教程,列表布局工作正常。
  • 所有文件和列表的permalinks正确工作。

问题:*对于教程,单个布局不调用“layout / tutorials /single.html”布局。相反,它使用“layout/_default/single.html”。

我尝试了以下几点:

  • 将type=“教程”序言设置添加到所有教程.md文件中
  • 将layout=“教程”序言设置添加到所有教程.md文件中
  • 在“layout/_tutorial.html”文件夹中添加一个“tutorials.html”文件(也尝试将其命名为“tutorials.html”)
  • 在“布局”文件夹中添加一个"tutorial.html“文件(与上面相同)

可悲的是,这些都没有用。

我的内容设置:

代码语言:javascript
复制
content
|__ posts
   |__ new_post.md
|__ tutorials
   |__ new-tutorial.md

我的布局设置(在主题文件夹中):

代码语言:javascript
复制
layouts
|__ _default
   |__ list.html
   |__ single.html
|__ posts
   |__ list.html
   |__ single.html
|__ tutorials
   |__ list.html
   |__ single.html
|__index.html

我的一个教程内容(new-tutorial.md):

代码语言:javascript
复制
+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
type: tutorial
layout: tutorial
+++

# Custom Content Headline

没有雨果的错误信息。我希望hugo打开"http://localhost:1313/tutorials/new-tutorial/“页面,其布局位于文件”layout /tutorials/single.html“中。

EN

回答 2

Stack Overflow用户

发布于 2019-10-04 15:00:32

您不应该在新教程中指定type: tutorialtype:tutorial

在默认情况下,Hugo将使用布局/教程/single.html作为教程一节,请参阅https://gohugo.io/templates/lookup-order/#examples-layout-lookup-for-regular-pages

新教程. for的最终结果如下

代码语言:javascript
复制
+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
+++

# Custom Content Headline
票数 0
EN

Stack Overflow用户

发布于 2022-09-09 20:53:27

问题已经解决了,问题在类型的定义上。默认情况下,Hugo会给出教程文件夹中的元素,类型教程,如果将其更改为教程,则必须使用教程htmls创建一个子文件夹,这是新的类型。

代码语言:javascript
复制
layouts
|__ _default
   |__ list.html
   |__ single.html
|__ posts
   |__ list.html
   |__ single.html
|__ tutorials
   |__ list.html
   |__ single.html
|__ tutorial
   |__ list.html
   |__ single.html
|__index.html

就像文件里说的

如果我没有说清楚,你可以读到这里这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58237421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档