Composition
The real power of xprompt is composition. Abody() method can return an array of renderables — strings, other prompts, or nulls. The framework recursively renders each element and joins the results with double newlines.
Basic Composition
"\n\n". Empty strings and nulls are silently skipped.
Conditional Sections
Returnnull to exclude a section. This keeps conditionals clean:
strict is false, the Constraints section is simply absent from the output — no empty lines, no placeholders.
Context Propagation
When a parent prompt renders a child via composition, the parent’s context automatically flows down. Children receive the merged context:with() merge it with the parent’s context — the child’s bindings take precedence for shared keys.
Nesting
Composition nests arbitrarily. A prompt can return an array containing prompts that themselves return arrays:flatten() function handles all the recursion. It traverses nested arrays, renders any Prompt or Stringable objects it finds, filters out nulls and empty strings, and joins everything with "\n\n".
Mixing Inline and Template-Backed Prompts
Composition doesn’t care how each piece generates its content. You can freely mix inline prompts, template-backed prompts, and raw strings in the same array:Next Steps
- Templates — use Twig files for content that’s easier to maintain as markup
- Structured Data — render lists, criteria, and taxonomies with NodeSet