跳转到内容

完整模板变量表

以下变量在所有页面模板中可用。

字段类型Jinja2Go TemplatesEJS
域名stringconfig.domain.Config.Domainconfig.domain
站点名称stringconfig.siteName.Config.SiteNameconfig.siteName
站点描述stringconfig.siteDescription.Config.SiteDescriptionconfig.siteDescription
头像stringconfig.avatar.Config.Avatarconfig.avatar
Logostringconfig.logo.Config.Logoconfig.logo

theme_config 对象 — 主题自定义配置

Section titled “theme_config 对象 — 主题自定义配置”

通过 config.json 的 customConfig 数组声明,在 GUI 中由用户设置:

引擎访问方式示例
Jinja2theme_config.<name>theme_config.primaryColor
Go Templates.ThemeConfig.<name>.ThemeConfig.primaryColor
EJStheme_config.<name>theme_config.primaryColor
变量类型说明
menus / .Menus[]Menu导航菜单列表
tags / .Tags[]Tag所有标签列表
now / .Nowtime.Time当前时间(Go time.Time 对象)

在列表页通过循环 posts 获取,在文章详情页通过 post 直接访问。

字段类型Jinja2Go TemplatesEJS
标题stringpost.title.Post.Title / .Titlepost.title
HTML 内容stringpost.content|safe.Post.Content<%- post.content %>
发布日期stringpost.date.Post.Date / .Datepost.date
格式化日期stringpost.dateFormat.Post.DateFormatpost.dateFormat
链接stringpost.link.Post.Link / .Linkpost.link
标签列表[]Tagpost.tags.Post.Tags / .Tagspost.tags
特色图片stringpost.feature.Post.Feature / .Featurepost.feature
是否置顶boolpost.isTop.Post.IsTop / .IsToppost.isTop
列表中隐藏boolpost.hideInList.Post.HideInListpost.hideInList
文件名stringpost.fileName.Post.FileNamepost.fileName
字段类型Jinja2Go TemplatesEJS
名称stringtag.name.Tag.Name / .Nametag.name
链接stringtag.link.Tag.Link / .Linktag.link
文章数inttag.count.Tag.Count / .Counttag.count
字段类型Jinja2Go TemplatesEJS
名称stringmenu.name.Namemenu.name
链接stringmenu.link.Linkmenu.link

仅在 index.htmlblog.html 中可用。

字段类型Jinja2Go TemplatesEJS
上一页stringpagination.prev.Pagination.Prevpagination.prev
下一页stringpagination.next.Pagination.Nextpagination.next

值为空字符串时表示已到达首页/末页。

仅在 memos.html 中通过 memos 列表可用。

字段类型说明
memo.contentstringMemo 内容(HTML)
memo.datestring发布日期
变量indexpostarchivestagtagsaboutfriendsmemosblog404
config**********
theme_config**********
menus**********
tags*********
now**********
posts****
post*
pagination**
tag/current_tag*
memos*
错误写法正确写法说明
post.urlpost.linkGridea 用 link 不用 url
post.imagepost.feature特色图片字段名为 feature
post.pinnedpost.isTop置顶字段名为 isTop
config.titleconfig.siteName站点名称字段为 siteName
config.urlconfig.domain域名字段为 domain
tag.posts_counttag.count简写为 count
pagination.previouspagination.prev简写为 prev
{{ val|default("x") }}{{ val|default:"x" }}Pongo2 用冒号不用括号