Global properties
731 words, 4-minute read
This section describes the properties available in the tacs
global object available to template literals in templates, content, and front matter. These properties are typically used to render page features such as menus, navigation, feeds, etc.
Core global properties #
The following properties are provided for page content by Publican irrespective of front matter definitions. Summary:
tacs property | description | |
---|---|---|
.root | web server directory | more |
.all | Map of posts indexed by slug | more |
.dir | Map of posts in root directories | more |
.tag | Map of posts with tags | more |
.tagList | array of tag objects | more |
.nav | nested array of navigation objects | more |
tacs.root
#
The web server root location. By default, Publican assumes files in the build directory are published to the server root, so ${ tacs.root }
returns /
.
The root server path can be changed in the configuration file.
tacs.all
#
A Map object of all published posts indexed by slug (relative to the build/
directory). For example, fetch the root home page:
// fetch the home page title
${ tacs.all.get('index.html')?.title }
The object is typically used for sitemaps and feeds where a list of all posts is required.
tacs.dir
#
A Map object of all published posts indexed by a root directory. Each item returns an ordered array of posts. For example, list all posts in the about
directory:
${ tacs.dir.get('about').map(
p => `<p>${ p.title }</p>`
) }
Publican can automatically generate directory index pages, so you should only require tacs.dir
in situations where you require specific lists, such as an RSS feed of recent posts.
tacs.tag
#
A Map object of all published posts indexed by normalized tag (lower case, spaces replaced with -
, etc.) Each item returns an ordered array of posts. For example, list all posts with an html
tag:
${ tacs.tag.get('html').map(
p => `<p>${ p.title }</p>`
) }
Publican can automatically generate tag index pages, so you should only require tacs.tag
in situations where you require specific lists.
tacs.tagList
#
An array of tag objects ordered by highest to lowest usage. Each object has 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
count
: the number of times the tag is used
Example:
[
{
tag: 'HTML',
ref: 'html',
link: '/tag/html/',
slug: 'tag/html/index.html',
count: 5
},
{
tag: 'Front Matter',
ref: 'front-matter',
link: '/tag/front-matter/',
slug: 'tag/front-matter/index.html',
count: 3
}
]
You should only require tacs.tagList
on a root tag page that lists all tags.
tacs.nav
#
tacs.nav
is a global nested array of post objects ordered for navigation menus, breadcrumb trails, etc. Each element in the array has post data
as well as a .children
property holding an array containing child data
items. Each child page has it’s own data
and children
array where appropriate.
It is generally necessary to recurse the tacs.nav
object, so this is easier in a global function rather than template. The following recipes provide code for:
Custom global properties #
tacs
global properties can be added, modified, or removed in the Publican configuration file so they can be reused across the site. You can add values or reusable functions that can be used in any template.