VOOZH about

URL: https://deepwiki.com/calevans/staticforge/6.3-template-variables

⇱ Template Variables | calevans/staticforge | DeepWiki


Loading...
Last indexed: 11 February 2026 (5f6a2a)
Menu

Template Variables

This page provides a complete reference for all variables available in StaticForge templates. Template variables are the data points that Twig templates use to render content, including page metadata, site configuration, navigation menus, and feature-generated data.

For information about template structure and inheritance, see Template Inheritance. For details about the TemplateRenderer service and template resolution logic, see Template Architecture.


Variable Sources

StaticForge aggregates template variables from multiple sources during the rendering pipeline. The TemplateVariableBuilder service collects data from:

  1. Content metadata: Extracted from frontmatter during file discovery
  2. Container variables: Global configuration loaded from .env and siteconfig.yaml
  3. Feature data: Structures built by features during event lifecycle
  4. Computed values: System-generated data like URLs and cache busters

Diagram: Template Variable Aggregation Pipeline


Sources:


Core Variables

Core variables are available in all templates and contain fundamental page and site information.

Content Variables

VariableTypeDescriptionExample
contentstringRendered HTML content of the page{{ content|raw }}
titlestringPage title from frontmatter{{ title }}
descriptionstringPage meta description{{ description }}
source_filestringRelative path to source content fileguide/index.md

Usage in templates:


Sources:

Site Variables

VariableTypeDescriptionConfiguration Source
site_namestringSite namesiteconfig.yaml > site.name
site_taglinestringSite taglinesiteconfig.yaml > site.tagline
site_base_urlstringBase URL with trailing slash.env > SITE_BASE_URL

Usage in templates:


Critical: Always use site_base_url for asset paths to ensure correct URL resolution across different page depths.

Sources:

Metadata Variables

Additional frontmatter fields are passed through to templates as top-level variables:

VariableTypeDescription
tagsarray/stringContent tags
categorystringContent category
datestringPublication date
herostringHero image path
templatestringTemplate name
Custom fieldsmixedAny additional frontmatter

Conditional rendering with metadata:


Sources:


Menu Variables

StaticForge supports two independent menu systems: static named menus and numbered content-based menus.

Diagram: Menu Variable Namespace


Sources:

Named Menus (Static)

Named menus are defined in siteconfig.yaml and accessible as menu_{name}.

Configuration:


Template access:


HTML output structure:


Sources:

Numbered Menus (Content-Based)

Numbered menus are generated from content files with menu: X.Y frontmatter notation.

VariableMenu NumberUsage
menu11Primary navigation
menu22Documentation sections
menu33Feature pages
menu44Development guides

Content frontmatter:


Template access:


Position notation:

  • 1.0 - First item in menu 1
  • 1.5 - Between 1.0 and 2.0
  • 1.1.1 - First child of item 1.1
  • 2.3 - Third item in menu 2

Sources:

Raw Menu Data

For advanced use cases, access structured menu data directly:


Sources:


Feature Variables

Features expose data through the features namespace. Each feature has its own sub-namespace containing generated data structures.

Diagram: Feature Variable Structure


Sources:

MenuBuilder Feature

VariableTypeDescription
features.MenuBuilder.files[N]arrayStructured menu data for menu N
features.MenuBuilder.html[N]stringPre-rendered HTML for menu N

Accessing menu data:


Sources:

ChapterNav Feature

Sequential navigation for documentation pages.

VariableTypeDescription
features.ChapterNav.pages[source_file]arrayNavigation data keyed by source file

Structure:


Template usage:


Sources:

Tags Feature

Tag cloud and tag list generation.

VariableTypeDescription
features.Tags.cloudstringHTML tag cloud
features.Tags.listarrayAll tags with counts

Template usage:


Sources:

Table of Contents (TOC)

VariableTypeDescription
tocstringGenerated table of contents HTML

Template usage:


Sources:

Category Variables

VariableTypeDescription
category_filesarrayFiles in the current category

File structure:


Template usage:


Sources:


Asset Variables

Asset variables are managed by the AssetManager and automatically injected if not explicitly rendered.

VariableTypeDescriptionInjection Point
stylesstring<link> tags for CSSBefore </head>
head_scriptsstring<script> tags for headBefore </head>
scriptsstring<script> tags for footerBefore </body>

Recommended placement:


Automatic injection: If these variables are not rendered in the template, TemplateRenderer automatically injects them before the closing </head> and </body> tags.

Sources:


Computed Variables

System-generated variables calculated during the build process.

VariableTypeDescription
cache_busterstringUnique build identifier for cache invalidation
urlstringAbsolute URL of current page

Usage:


Sources:


Variable Access Patterns

Diagram: Variable Resolution Flow


Sources:

Checking Variable Existence

Always check for variable existence before use:


Sources:

Iterating Collections


Sources:

Rendering Raw HTML

Use the raw filter for HTML content to prevent escaping:


Warning: Only use raw for trusted content. Never use it for user input.

Sources:


Form Variables

Forms feature provides variables for embedded form rendering.

VariableTypeDescription
endpointstringForm submission URL
fieldsarrayField definitions
success_messagestringSuccess message text
error_messagestringError message text
submit_textstringSubmit button text
challenge_urlstringAltcha spam protection URL

Configuration:


Template usage:


Sources:


Custom Feature Variables

Custom features can expose data through the features namespace:

In feature class:


In template:


Sources:


Variable Namespace Summary

NamespacePurposeSource
Top-levelCore page variablesFrontmatter, container
site_*Site configurationsiteconfig.yaml, .env
menu_*Named static menussiteconfig.yaml
menu1..4Numbered content menusFrontmatter menu: X.Y
features.*Feature-generated dataFeature event listeners
styles, scripts, etc.Asset injectionAssetManager

Sources: