Skip to main content

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

The withConfig() method returns a clone of the prompt with the given config applied:

Registry-Wide Config

Pass config to the PromptRegistry 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:
  1. Instance config — set via withConfig() on the prompt instance
  2. templateDir compatibility — if $templateDir is set on the class, a Twig config with that resource path is created
  3. Default Twig — bare TemplateEngineConfig::twig() with no resource path
This means existing prompts with $templateDir continue to work unchanged.

Presets

Load configuration from YAML preset files using fromPreset():
This searches for my-templates.yaml in the standard preset directories:
You can also provide a specific base path:

Quick Reference