首页 > 解决方案 > hugo 不会渲染单页布局,而是使用 _default 单页布局

问题描述

)

我正在尝试为 hugo.io 创建自己的主题。到目前为止,一切正常。我唯一的问题是,我无法让 hugo 为单节内容呈现自定义布局。

对于帖子,这很好用:

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

我尝试了以下方法:

可悲的是,这些都不起作用

我的内容设置:

content
|__ posts
   |__ new_post.md
|__ tutorials
   |__ new-tutorial.md

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

layouts
|__ _default
   |__ list.html
   |__ single.html
|__ posts
   |__ list.html
   |__ single.html
|__ tutorials
   |__ list.html
   |__ single.html
|__index.html

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

+++
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/,其布局位于文件“layouts/tutorials/single.html”中

标签: hugo

解决方案


你不应该在你的情况下在 new-tutorial.md 中指定type: tutorialand 。type:tutorial

Hugo 将默认使用 layouts/tutorials/single.html 作为教程部分,请参阅https://gohugo.io/templates/lookup-order/#examples-layout-lookup-for-regular-pages

new-tutorial.md 的最终结果将如下所示

+++
title = "My new Tutorial"
date: 2019-10-04T14:10:46+02:00
draft: false
+++

# Custom Content Headline

推荐阅读