> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instructorphp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

# Templates Package Cheatsheet

## Template Creation

```php theme={null}
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

```php theme={null}
Template::text(string $pathOrDsn, array $variables): string
Template::messages(string $pathOrDsn, array $variables): Messages
```

## Fluent API

```php theme={null}
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

```php theme={null}
toText(): string
toMessages(): Messages
toMessageStore(): MessageStore
toArray(): array
```

## Message Rendering

```php theme={null}
renderMessage(Message $message): Message    // render template variables in message text parts
renderMessages(Messages $messages): Messages // render template variables in all messages
```

## Introspection

```php theme={null}
config(): TemplateEngineConfig
template(): string
params(): array
variables(): array
info(): TemplateInfo
validationErrors(): array
```

## TemplateEngineConfig

```php theme={null}
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

```php theme={null}
$text = Template::forEngine('twig')
    ->get('prompts/demo-twig/hello')
    ->with(['name' => 'World'])
    ->toText();

$messages = Template::messages('twig:prompts/demo-twig/hello', ['name' => 'World']);
```
