Content properties
1,210 words, 7-minute read
This section describes the content properties available in the data
object available to template literals in templates, content, and front matter. These properties are typically used to render the main page content and meta tags.
Core post properties #
The following properties are provided for page content by Publican irrespective of front matter definitions. Summary:
data property | description | |
---|---|---|
.title | title | more |
.menu | title for menus | more |
.content | main content | more |
.contentRendered | final rendered main content | more |
.date | date created | more |
.publish | publication date or draft | more |
.index | false or indexing frequency | more |
.priority | 0 (least) to 1 (most) important | more |
.tags | array of tag data | more |
.wordCount | number of words in content | more |
.postnext | data of next post | more |
.postback | data of previous post | more |
.pagination | object for directory and tag index pages | more |
.filename | content filename | more |
.template | template filename | more |
.slug | build filename | more |
.link | full link to page | more |
.directory | name of root directory | more |
.isMD | content is markdown | more |
.isHTML | built file is HTML | more |
.isXML | built file is XML | more |
.debug | enable debugging | more |
data.title
#
The page title for headings, <title>
tags, feeds, etc.
data.menu
#
Where necessary, an abbreviated page title for menus and other navigation links.
data.content
#
The main page content. Markdown content is already converted to HTML.
data.contentRendered
#
Content such as RSS feeds needs to access the fully-rendered content of pages. Publican ensures this content is rendered last to ensure fully-processed page content is available.
data.date
#
The Date()
of the post, or null
if not defined.
In general, you will not want to output raw dates, but use a formatting function to output human-friendly dates for a specific locale.
data.publish
#
A Boolean value indicating whether the page is published according to the front matter publish
value.
- Any content set to
draft
,false
, or a date beyond today is not rendered in a production build. - Development builds render all posts.
The value is not normally useful since it will always be true
!
data.index
#
Either false
or a string denoting the sitemap indexing frequency (daily
, weekly
, monthly
, yearly
).
The value can be used to remove pages from index pages and navigation menus. You could also check it when generating sitemaps.
data.priority
#
The post priority (SEO importance) from 0
to 1
. The default is 0.1
.
The value is most used for XML sitemaps and to order pages in Publican navigation.
data.tags
#
Publican can automatically generate paginated pages of links to posts with specific tags. The data.tags
value is an array of objects with the following properties:
tag
: the tag name, e.g.Front Matter
ref
: a normalized reference name, e.g.front-matter
link
: the link to the tag index page, e.g./tag/front-matter/
slug
: the tag index page build file location, e.g.tag/front-matter/index.html
Example:
[
{
tag: 'HTML',
ref: 'html',
link: '/tag/html/',
slug: 'tag/html/index.html'
},
{
tag: 'Front Matter',
ref: 'front-matter',
link: '/tag/front-matter/',
slug: 'tag/front-matter/index.html'
}
]
Code to output the page’s tags with links to their index pages:
${ data?.tags?.map(
t => `<p><a href="${ t.link }">${ t.tag }</a></p>`
) }
data.wordCount
#
The number of words in the content as an integer.
data.postnext
#
The data
object of the next post (according to the content order). Usage example:
${
data?.postnext?.title &&
`<p class="next"><a href="${ data.postnext.link }">
next post: ${ data.postnext.title }
</a></p>`
}
data.postback
#
The data
object of the previous post (according to the content order). Usage example:
${
data?.postback?.title &&
`<p class="next"><a href="${ data.postback.link }">
previous post: ${ data.postback.title }
</a></p>`
}
data.paginatation
#
Generated root directory and tag index pages provide a data.pagination
object with the following properties.
name | description |
---|---|
.page | an array of page data objects available in the current page |
.pageTotal | total number of pages |
.pageCurrent | current page number (zero based) |
.pageCurrent1 | current page number (one based) |
.subpageFrom1 | post number from |
.subpageTo1 | post number to |
.hrefBack | link to previous paginated page |
.hrefNext | link to next paginated page |
.href | array of links to all paginated pages |
data.filename
#
The name of content file relative to the content directory, e.g. #index.md
or about/contact-us.md
.
The value is rarely useful, but can be referenced for sorting.
data.template
#
The root template being used.
data.slug
#
The rendered filename relative to the build directory, e.g. index.html
or about/contact-us/index.html
.
The value is rarely required, but may be practical if you want to modify content for a specific output file.
data.link
#
The full link to the page, including the root path.
The value is rarely required for the current page, but is used in navigation and pagination objects.
data.directory
#
The root content path/directory, typically used for directory pagination.
data.isMD
#
A Boolean value which is true
when the content is provided in markdown format.
This value is used internally my Publican but may be useful if you want to modify markdown-generated content in some way.
data.isHTML
#
A Boolean value which is true
when the rendered file is HTML
This may be useful if you need to modify HTML content.
data.isXML
#
A Boolean value which is true
when the rendered file is XML
This may be useful if you need to modify XML content.
data.debug
#
A value passed by front matter which can be used to enable debugging output in functions or elsewhere.
Custom page properties #
Page data
properties be added, modified, or removed from data
objects using any of the following methods (which show how to set an author).
Set front matter values:
markdown
--- title: My Post date: 2025-01-23 author: Craig Buckler ---
Run a
processContent
function hook when content is initially loaded:publican.config.js
examplepublican.config.processContent.add( (filename, data) => data.author = data.author || 'Craig Buckler' );
Run a
processPreRender
function hook just before post rendering:publican.config.js
examplepublican.config.processPreRender.add( (data) => data.author = data.author || 'Craig Buckler' );
Run a
.processRenderStart
function hook to process all post data before rendering:publican.config.js
examplepublican.config.processRenderStart.add( () => tacs.all.forEach( post => post.author = post.author || 'Craig Buckler' ) );