Leafpub themes are made up of multiple Handlebar templates, some of which are required. This post describes what each template does and the data that's made available to them.

Templates

The following templates are required in every Leafpub theme. Each template is rendered in the root context with a specific set of data provided to it.

Tip: Templates use the .hbs file extension, so make sure your favorite text editor or IDE is configured to open them.

author.hbs

Renders an author page with corresponding posts. The following data is available:

  • author – collection of author data
  • posts – collection of posts by this author
  • pagination – collection of pagination data for posts by this author

blog.hbs

Renders the blog index. The following data is available:

  • posts – collection of posts
  • pagination – collection of pagination data for posts

error.hbs

Renders an error page (such as a 404 error). No data is provided, but you can use special variables to detect the error code.

page.hbs / post.hbs

Renders a page or a post. Both of these templates receive the following data:

  • post – collection of post data

search.hbs

Renders a search page or a search results page. The following data is available:

  • query – string containing the user's search query
  • posts – collection of matching posts
  • pagination – collection of pagination data for posts matching this query

tag.hbs

Renders a tag page with corresponding posts. The following data is available:

  • tag – collection of tag data
  • posts – collection of posts with this tag
  • pagination – collection of pagination data for posts with this tag

Special Variables

Leafpub make additional data available to every template. The following special variables start with @ and are accessible globally from any context:

  • @cookies – collection of cookies that currently exist
  • @meta
    • title – the meta title for the current page
    • description – the meta description for the current page
    • editable – true if the template is being rendered in the editor
    • preview – true if the template is being rendered as a preview
    • ld_json – meta data for Schema.org (via JSON linked data)
    • open_graph – meta data for Open Graph
    • twitter_card – meta data for Twitter cards
  • @leafpub
    • version – the current Leafpub version
  • @request
    • get – collection of query string parameters attached to the page
    • post – collection of post data attached to the page
    • host – the current host (example: example.com)
    • homepage – true when rendering the homepage
    • ip – the visitor's IP address
    • method – the HTTP method used to request the page (GET/POST)
    • referer - the referring URL
    • time – time the request was made
    • user_agent – the visitor's user agent string
  • @settings – a collection of settings (only relevant properties shown)
    • title – the website's title
    • tagline – the website's tagline
    • logo – the website's logo
    • favicon – the website's favicon
    • cover – the website's cover photo
  • @template – string containing the name of the template being rendered (e.g. post, page, etc.)
  • @user – if a Leafpub user is logged in, this will contain a collection of their user data