Configuration
By default, xprompt uses Twig with$templateDir paths set on individual prompt classes. For centralized control — shared resource paths, cache directories, or preset-based configuration — use TemplateEngineConfig.
Per-Prompt Config
ThewithConfig() method returns a clone of the prompt with the given config applied:
Registry-Wide Config
Pass config to thePromptRegistry constructor. Every prompt retrieved via get() will have this config applied:
Config Resolution
When a prompt resolves its template engine config, it follows this priority:- Instance config — set via
withConfig()on the prompt instance - templateDir compatibility — if
$templateDiris set on the class, a Twig config with that resource path is created - Default Twig — bare
TemplateEngineConfig::twig()with no resource path
$templateDir continue to work unchanged.
Presets
Load configuration from YAML preset files usingfromPreset():
my-templates.yaml in the standard preset directories:
Quick Reference
| Method | Purpose |
|---|---|
TemplateEngineConfig::twig($resourcePath, $cachePath) | Twig engine with paths |
TemplateEngineConfig::fromPreset($name) | Load from YAML preset file |
TemplateEngineConfig::fromArray($data) | Create from array |
$config->withOverrides($values) | Merge overrides into existing config |
$prompt->withConfig($config) | Clone prompt with config |