I was hoping to indicate content’s draft status with something like the following:
{{ if .Site.BuildDrafts }}
{{ if .Params.draft }}<p>Draft</p>{{ end }}
{{ end }}
However, there doesn’t seem to be a .Params.draft
or any other relevant variable available to a single/item/content/page template.
Does anyone know if it’s possible without including a second/repetitive front matter variable, such as draft2
? Thanks.
Draft is a page variable, so you can access it as .Draft.
{{ if .Site.BuildDrafts }}
<h2>Building Drafts</h2>
{{ if .Draft }}<p>Draft</p>{{ end }}
{{ end }}
Great - thanks. Pull request for docs submitted.
Shortcodes can help since they can be used directly in your content:
<!-- layouts/shortcodes/flagDrafts.html -->
{{ if .Page.Draft }}{{ .Inner }}{{ end }}
That can be used in your content as needed:
{{% flagDrafts %}}This is a draft version{{% /flagDrafts %}}
1 Like