Warning! This documentation is a work in progress. Expect things to be out of date and not actually work according to instructions.

Templates

Templating is based on the Jinja templating language, which was ported to Java via the jinjava project.

A basic template looks as follows:

<h1>{ page.title }}</h1>
{% if page.tags %}
    <div>Tags:
       {% for tag in page.tags %}
        <span class="tag">{ tag }}</span>
        {% endfor %}
    </div>
{% endif %}

Templates support inheritence. So I can have a base template base.jinja:

<html>
    <head>
        <title>{ meta.title }}</title>
        { assets.bundle("site.bundle.css") }}
    </head>
    <body>
        <nav>...</nav>
        {% block main_content %}
        {% endblock %}
        <footer>...</footer>
    </body>
    </html>

And then extend that template and override certain parts:

{% extends "base.jinja" %}
{% block main_content %}
<h3>{ page.title }}</h3>
<div>{ page.content }}</div>
{% endblock %}

Any Stallion ModelController that you have registered is accessible via its bucket name. You can call methods on the controller to fetch items:

{% for recent_page in pages.filter('published', true).sort('publishDate', 'desc').pager(1).items %}
    <a href="{ recent_page.permalink }}">{ recent_page.title }}</a>
{% endfor %}
  

There a bunch of variables injected into the template context that you can access:

  • user – the user object, if the user is logged in. Popular fields are user.authorized ( a boolean indicating if the user exists, is enabled, and is logged in), user.displayName, user.email, user.role. See API docs for io.stallion.users.User.
  • request – the request object. See API docs for io.stallion.StRequest object here.
  • site – The site information, as you defined in your settings. Popular fields are site.name, site.metaDescription and site.url. See API docs for io.stallion.Site.
  • meta – Information about the current page. Popular fields are meta.title, meta.description. See io.stallion.requests.MetaInformation
  • utils – helpers such as utils.slugify(string). See io.stallion.utils.GeneralUtils.
  • now – the current time, in the local timezone as defined in your settings, as a ZonedDateTime object.
  • dateUtils – has methods for formatting dates as strings. See io.stallion.utils.DateUtils
  • styleSettings – default styles that you maybe defined in your stallion.toml settings.
  • assets – controller for getting the URL’s of static assets and bundles. See the section on “Javascript and CSS Asset Bundling” for usage.

More extensive documentation for template features is contained in the Jinja documentation.

© 2018 Stallion Software LLC