EEx template rendering with three-layer composition.
Templates are rendered in three layers:
- Content body — Markdown already rendered to HTML (from
Sayfa.Content) - Layout template — Wraps content body (e.g.,
article.html.eex,page.html.eex) - Base template — HTML shell (
<html>,<head>,<body>), wraps layout output
Layout Selection
The layout is determined by (in priority order):
- Front matter
layout:key - Content type directory default (
articles/→article,pages/→page) - Fallback to
page
Examples
# Render an EEx string
{:ok, html} = Sayfa.Template.render_string("<h1><%= @title %></h1>", title: "Hello")
# Full three-layer render
{:ok, html} = Sayfa.Template.render_content(content, config: config)
Summary
Functions
Renders content through the full three-layer template pipeline.
Renders an error page (e.g. 404) through the base template.
Renders an EEx template file with the given assigns.
Renders a list page through the three-layer template pipeline.
Renders an EEx string with the given assigns.
Functions
@spec render_content( Sayfa.Content.t(), keyword() ) :: {:ok, String.t()} | {:error, term()}
Renders content through the full three-layer template pipeline.
- Determines the layout from content metadata or content type
- Renders the layout template with content body as
@inner_content - Wraps the result in the base template
Options
:config— resolved config map (required):layouts_dir— override layouts directory (optional, derived from config)
Examples
config = Sayfa.Config.resolve([])
{:ok, html} = Sayfa.Template.render_content(content, config: config)
Renders an error page (e.g. 404) through the base template.
Uses the given layout name (e.g. "404") and wraps it in the base template
with minimal assigns.
Examples
{:ok, html} = Sayfa.Template.render_error_page("404", config: config)
Renders an EEx template file with the given assigns.
Examples
Sayfa.Template.render_file("priv/default_theme/layouts/page.html.eex",
inner_content: "<p>Hello</p>",
content: content,
site: config
)
Renders a list page through the three-layer template pipeline.
Used for archive pages (tags, categories) and content type index pages.
Uses the list.html.eex layout with @contents and @pagination assigns.
Options
:config— resolved config map (required):layouts_dir— override layouts directory (optional):contents— list of content items to display (required):page_title— title for the page (required):pagination— pagination struct (optional, nil for non-paginated)
Renders an EEx string with the given assigns.
Examples
iex> Sayfa.Template.render_string("Hello <%= @name %>", name: "World")
{:ok, "Hello World"}