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:
- Templates live inside real HTML documents
- Data is sourced from the site graph, not external databases
- HTTP semantics (resources, selectors, authorization, content-types) remain the primary abstraction
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:
text/liquid
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:
- Bound resources
- The HTTP request object
- 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:
- The selector is evaluated across the site graph
- Matching elements are materialized as resource objects
- The Liquid engine renders the subtree
- 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:
- Scoped to the annotated element
- Side-effect free
- Deterministic
Templates cannot:
- Mutate documents
- Create resources
- Perform I/O
- Issue HTTP requests
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:
- Server-side rendering embedded in HTML
- Site-graph resource binding via CSS selectors
- Request-aware conditional rendering
- Deterministic, cacheable execution
- Zero application server code
It is designed to be powerful enough for dynamic documents, and constrained enough to remain predictable infrastructure.