HUGO
Menu
GitHub 87548 stars Mastodon

Hugo Param 短代碼

使用 param 短代碼將參數從 front matter 或站點配置插入到你的內容中。

要覆蓋 Hugo 內置的 param 短代碼,請將 源代碼 復制到 layouts/_shortcodes 目錄中同名文件中。

param 短代碼渲染來自 front matter 的參數,回退到同名的站點參數。如果參數不存在,短代碼會拋出錯誤。

content/example.md
---
title: 示例
date: 2025-01-15T23:29:46-08:00
params:
  color: red
  size: medium
---

我們找到了一件 {{% param "color" %}} 襯衫。

Hugo 渲染為:

<p>我們找到了一件紅色襯衫。</p>

通過 鏈接 標識符 來訪問嵌套值:

{{% param my.nested.param %}}

Last updated: January 1, 0001
Improve this page