Templates
When prompt content is mostly markup — instructions, rubrics, output format specifications — a Twig template is easier to maintain than a PHP string. Xprompt integrates with thepackages/templates engine so you can keep your .twig files next to your prompt classes.
Template-Backed Prompt
Set$templateFile and $templateDir on your prompt class:
templates/analyze.twig:
body() method you inherit handles loading, parsing, and rendering automatically.
Colocating Templates
The recommended layout places templates alongside the prompt classes that use them:$templateDir = __DIR__ . '/templates', keeping paths relative and portable.
Front Matter
Templates can include YAML front matter for metadata. The front matter is parsed but not rendered — it’s available via themeta() method:
meta() to make decisions about which model to use or to track prompt versions.
Introspection
Template-backed prompts expose their variables and validation state:Blocks
Blocks let you inject pre-rendered prompt content into template variables. Define block classes, list them in$blocks, and reference them in your template as {{ blocks.ClassName }}:
document.twig:
isBlock = true flag hides them from registry listings — they’re internal building blocks, not standalone prompts.
Overriding body()
If you need to add logic around template rendering, overridebody() and call renderTemplate() yourself, or compose the template prompt with other elements:
Next Steps
- Structured Data — render lists and rubrics with NodeSet
- Variants & Registry — swap template-backed prompts without changing callers