Skip to content

_templates

_templates

Minimal template rendering via {{VAR}} token replacement.

render_template(template_path, variables)

Read template_path and replace {{KEY}} tokens with variables values.

Source code in src/terok_sandbox/_util/_templates.py
def render_template(template_path: Path, variables: dict) -> str:
    """Read *template_path* and replace ``{{KEY}}`` tokens with *variables* values."""
    content = template_path.read_text()
    for k, v in variables.items():
        content = content.replace(f"{{{{{k}}}}}", str(v))
    return content