Templates System

The template system allows you to generate files and directories from templates. It forms the foundation of Angreal’s project creation capabilities.

Overview

Angreal’s template system consists of:

  • Template Rendering - Generate files from templates
  • Directory Rendering - Process entire directories of templates
  • Context Generation - Create variables for templates
  • angreal.toml Format - Configure template variables and prompts

Templates use the Tera templating engine, which provides Jinja2-like syntax.

Key Components

ComponentDescriptionDocumentation
render_templateRender a single template fileAPI Reference
render_directoryProcess a directory of templatesAPI Reference
generate_contextCreate context variables for templatesAPI Reference
angreal.tomlDefine template variables and promptsFormat Reference

Comprehensive Guide

For a complete walkthrough of using templates, see the Template System Guide.

Example

import angreal
import os

def create_project():
    # Generate context for templates
    context = angreal.generate_context(
        template_path="templates/project",
        interactive=True
    )

    # Render a directory of templates
    angreal.render_directory(
        source_directory="templates/project",
        target_directory=context.get("project_name", "new-project"),
        context=context
    )