Templates Package Cheatsheet
Template Creation
Copy
Template::make(string $pathOrDsn)
Template::fromDsn(string $dsn) // engine:path
Template::twig()
Template::blade()
Template::arrowpipe()
Template::forEngine(string $engine)
new Template(path: '', config: ?TemplateEngineConfig, driver: ?CanHandleTemplate)
Static Shortcuts
Copy
Template::text(string $pathOrDsn, array $variables): string
Template::messages(string $pathOrDsn, array $variables): Messages
Fluent API
Copy
withConfig(TemplateEngineConfig $config): self
withDriver(CanHandleTemplate $driver): self
get(string $path): self
withTemplate(string $path): self
withTemplateContent(string $content): self
from(string $content): self
with(array $values): self
withValues(array $values): self
Outputs
Copy
toText(): string
toMessages(): Messages
toMessageStore(): MessageStore
toArray(): array
Message Rendering
Copy
renderMessage(Message $message): Message // render template variables in message text parts
renderMessages(Messages $messages): Messages // render template variables in all messages
Introspection
Copy
config(): TemplateEngineConfig
template(): string
params(): array
variables(): array
info(): TemplateInfo
validationErrors(): array
TemplateEngineConfig
Copy
TemplateEngineConfig::fromPreset(string $preset, ?string $basePath = null): self
TemplateEngineConfig::fromArray(array $config): self
TemplateEngineConfig::twig(string $resourcePath = '', string $cachePath = ''): self
TemplateEngineConfig::blade(string $resourcePath = '', string $cachePath = ''): self
TemplateEngineConfig::arrowpipe(string $resourcePath = '', string $cachePath = ''): self
Minimal Examples
Copy
$text = Template::forEngine('twig')
->get('prompts/demo-twig/hello')
->with(['name' => 'World'])
->toText();
$messages = Template::messages('twig:prompts/demo-twig/hello', ['name' => 'World']);