LinkTitle
Syntax
PAGE.LinkTitle
Returns
string
LinkTitle
方法返回在 front matter 中定义的 linkTitle
字段,如果未定义则回退到 Title
方法返回的值。
content/articles/healthy-desserts.md
---
linkTitle: Dessert recipes
title: Seventeen delightful recipes for healthy desserts
---
+++
linkTitle = 'Dessert recipes'
title = 'Seventeen delightful recipes for healthy desserts'
+++
{
"linkTitle": "Dessert recipes",
"title": "Seventeen delightful recipes for healthy desserts"
}
{{ .LinkTitle }} → Dessert recipes
如上所示,当页面标题过长时,在 front matter 中定义链接标题非常有利。在模板中生成锚元素时使用它:
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>