Expand description
Two-pass template rendering with style tag processing.
This module provides the core rendering pipeline that transforms templates and data into styled terminal output. Templates are processed in two passes: template engine for logic, then BBParser for style tags.
§Template Engines
Two template engines are available:
| Engine | Syntax | Features | Use When |
|---|---|---|---|
MiniJinjaEngine | {{ var }} | Loops, conditionals, filters, includes | Full template logic needed |
SimpleEngine | {var} | Variable substitution only | Simple output, smaller binary |
§MiniJinja (Default)
Full-featured Jinja2-compatible engine. File extensions: .jinja, .jinja2, .j2
[title]{{ name | upper }}[/title] has {{ count }} items
{% for item in items %}{{ item.name }}{% endfor %}§Simple Engine
Lightweight format-string style substitution. File extension: .stpl
[title]{name}[/title] has {count} items
{user.profile.email}§Two-Pass Rendering
Templates are processed in two distinct passes, which is why style tags use
bracket notation ([name]...[/name]) instead of template syntax:
Pass 1 - Template Engine: Variable substitution (and control flow for MiniJinja).
Template: [title]{{ name | upper }}[/title] has {{ count }} items
After: [title]WIDGET[/title] has 42 itemsPass 2 - BBParser: Style tags converted to ANSI codes (or stripped).
Input: [title]WIDGET[/title] has 42 items
Output: \x1b[1;32mWIDGET\x1b[0m has 42 itemsThis separation keeps template logic independent from styling concerns.
§Which Render Function?
Choose based on your needs:
| Function | Use When |
|---|---|
render | Simple case, let Standout auto-detect everything |
render_with_output | Honoring --output flag (Term/Text/Auto) |
render_with_mode | Full control over output mode AND color mode |
render_auto | CLI with --output=json support (skips template for structured modes) |
The “auto” in render_auto refers to template-vs-serialization dispatch,
not color detection. Structured modes (JSON, YAML, XML, CSV) serialize data
directly, skipping the template entirely.
§Style Tags in Templates
Use bracket notation for styling (works with both engines):
[title]{{ name }}[/title] - [muted]{{ description }}[/muted] // MiniJinja
[title]{name}[/title] - [muted]{description}[/muted] // SimpleTags can nest, span multiple lines, and contain template logic. Unknown tags
show a ? marker ([unknown?]text[/unknown?]) — use validate_template
to catch typos at startup or in tests.
§Template Registry
For file-based templates, use TemplateRegistry:
let mut registry = TemplateRegistry::new();
registry.add_from_files(walk_template_dir("./templates")?)?;
let content = registry.get_content("config")?;Resolution priority: inline templates → embedded (compile-time) → file-based.
Supported extensions: .jinja, .jinja2, .j2, .stpl, .txt (in priority order).
§Key Types
Renderer: Pre-compiled template renderer for repeated renderingTemplateRegistry: Template resolution from multiple sourcesTemplateEngine: Trait for pluggable template backendsMiniJinjaEngine: Full-featured Jinja2 engine (default)SimpleEngine: Lightweight format-string enginevalidate_template: Check templates for unknown style tags
§See Also
crate::theme: Theme and style definitionscrate::tabular: Column formatting utilities and template filterscrate::context: Context injection for templates
Re-exports§
pub use registry::walk_template_dir;pub use registry::RegistryError;pub use registry::ResolvedTemplate;pub use registry::TemplateFile;pub use registry::TemplateRegistry;pub use registry::TEMPLATE_EXTENSIONS;
Modules§
Structs§
- Mini
Jinja Engine - MiniJinja-based template engine.
- Renderer
- A renderer with pre-registered templates.
- Simple
Engine - A lightweight template engine using format-string style substitution.
Traits§
- Template
Engine - A template engine that can render templates with data.
Functions§
- register_
filters - Registers standout’s custom filters with a MiniJinja environment.
- render
- Renders a template with automatic terminal color detection.
- render_
auto - Auto-dispatches between template rendering and direct serialization.
- render_
auto_ with_ context - Auto-dispatches with context injection support.
- render_
auto_ with_ engine - Auto-dispatches rendering using a provided TemplateEngine.
- render_
auto_ with_ spec - Auto-dispatches with granular control over structured output.
- render_
with_ context - Renders a template with additional context objects injected.
- render_
with_ mode - Renders a template with explicit output mode and color mode control.
- render_
with_ output - Renders a template with explicit output mode control.
- render_
with_ vars - Renders a template with additional variables injected into the context.
- validate_
template - Validates a template for unknown style tags.