Templating

Pagelove supports server-side templating directly inside HTML documents. Templates are evaluated as part of normal request processing and operate over the document tree, site resources, and the active HTTP request. To use Templating, Server Side Processing Instructions must be enabled.

The core design goals are:

This allows HTML to function as both application code and data surface, without introducing a parallel runtime or framework.

Enabling templating

Templating is enabled by attaching the pagelove:template attribute to any element.

<section pagelove:template="text/liquid">
    ...
</section>

The attribute value is the template engine MIME type. Currently supported engines include:

Additional engines may be added in future.

Only the subtree rooted at the annotated element is processed by the template engine. The remainder of the document is left unchanged.

Data sources

Templates can access three primary categories of data:

  1. Bound resources
  2. The HTTP request object
  3. Template-local variables

Example: listing team members

<ul pagelove:template="text/liquid"
    resource:users="[id][itemtype='http://example.com/TeamMember']">
    {% assign users = users | sort: 'fullname' %}
    {%- for user in users -%}
    <li>
        <a href="{{ user['@id'] }}">{{ user.fullname }}</a> ({{ user.email }})
    </li>
    {%- endfor -%}
</ul>

Processing steps:

  1. The selector is evaluated across the site graph
  2. Matching elements are materialized as resource objects
  3. The Liquid engine renders the subtree
  4. The rendered HTML replaces the original template subtree

Request object

Templates have access to the active HTTP request via the request object.

Example:

<section class="debug" pagelove:template="text/liquid">
<pre>{{ request | json: 2 }}</pre>
</section>

Template scope

Template execution is:

Templates cannot:

They are strictly a rendering mechanism.

Includes vs templates

Pagelove provides two orthogonal composition mechanisms:

Feature Purpose
<pagelove:include> Structural composition (server-side DOM inclusion)
pagelove:template Data-driven rendering

They are often used together:

<pagelove:include selector="#site header"></pagelove:include>
<section pagelove:template="text/liquid">
    ...
</section>
<pagelove:include selector="#site footer"></pagelove:include>

Summary

Pagelove templating provides:

It is designed to be powerful enough for dynamic documents, and constrained enough to remain predictable infrastructure.