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 propertydescription
.titletitlemore
.menutitle for menusmore
.contentmain contentmore
.contentRenderedfinal rendered main contentmore
.datedate createdmore
.publishpublication date or draftmore
.indexfalse or indexing frequencymore
.priority0 (least) to 1 (most) importantmore
.tagsarray of tag datamore
.wordCountnumber of words in contentmore
.postnextdata of next postmore
.postbackdata of previous postmore
.paginationobject for directory and tag index pagesmore
.filenamecontent filenamemore
.templatetemplate filenamemore
.slugbuild filenamemore
.linkfull link to pagemore
.directoryname of root directorymore
.isMDcontent is markdownmore
.isHTMLbuilt file is HTMLmore
.isXMLbuilt file is XMLmore
.debugenable debuggingmore

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.

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:

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.

namedescription
.pagean array of page data objects available in the current page
.pageTotaltotal number of pages
.pageCurrentcurrent page number (zero based)
.pageCurrent1current page number (one based)
.subpageFrom1post number from
.subpageTo1post number to
.hrefBacklink to previous paginated page
.hrefNextlink to next paginated page
.hrefarray 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.

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).

  1. Set front matter values:

    markdown

    ---
    title: My Post
    date: 2025-01-23
    author: Craig Buckler
    ---
    
  2. Run a processContent function hook when content is initially loaded:

    publican.config.js example

    publican.config.processContent.add(
      (filename, data) => data.author = data.author || 'Craig Buckler'
    );
    
  3. Run a processPreRender function hook just before post rendering:

    publican.config.js example

    publican.config.processPreRender.add(
      (data) => data.author = data.author || 'Craig Buckler'
    );
    
  4. Run a .processRenderStart function hook to process all post data before rendering:

    publican.config.js example

    publican.config.processRenderStart.add(
      () => tacs.all.forEach(
        post => post.author = post.author || 'Craig Buckler'
      )
    );