PHPackages                             quellabs/canvas-plates - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. quellabs/canvas-plates

ActiveLibrary[Templating &amp; Views](/categories/templating)

quellabs/canvas-plates
======================

Plates template engine integration for the Canvas PHP framework

1.0.4(3w ago)00MITPHP

Since Mar 11Pushed 3w agoCompare

[ Source](https://github.com/quellabs/canvas-plates)[ Packagist](https://packagist.org/packages/quellabs/canvas-plates)[ Docs](https://github.com/quellabs/canvas-plates)[ RSS](/packages/quellabs-canvas-plates/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (15)Versions (6)Used By (0)

Plates Template Engine for Canvas Framework
===========================================

[](#plates-template-engine-for-canvas-framework)

A Plates template engine implementation for the Canvas PHP framework that provides a consistent interface for template rendering operations.

Features
--------

[](#features)

- **Interface Compliance**: Implements `TemplateEngineInterface` for consistent template engine operations
- **Native PHP Templates**: No new syntax to learn — templates are plain PHP files
- **Global Variables**: Support for framework-wide template variables
- **Custom Functions**: Easy registration of custom functions accessible in all templates
- **String Templates**: Render templates from strings as well as files
- **Multiple Template Paths**: Support for namespaced template directories (Plates "folders")

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require quellabs/canvas-plates
```

The package includes Plates as a dependency and automatically copies the configuration file to `/config/plates.php`. No additional setup is required - just register the service provider in your Canvas framework configuration.

Configuration
-------------

[](#configuration)

The package automatically creates a configuration file at `config/plates.php` during installation.

Selecting the Default Template Engine
-------------------------------------

[](#selecting-the-default-template-engine)

To use Plates as the default template engine across your application, set the following in `config/app.php`:

```
'template_engine' => 'plates',
```

Once set, rendering templates in your controllers works as normal:

```
/**
 * @Route("/")
 * @return Response
 */
public function index(Request $request): Response {
    return $this->render('pages/home', [
        'title' => 'Welcome',
    ]);
}
```

If you need to mix multiple template engines in the same project, you can request a specific engine explicitly via the container:

```
$template = $container->for('smarty')->get(TemplateEngineInterface::class);
$template = $container->for('plates')->get(TemplateEngineInterface::class);
$template = $container->for('blade')->get(TemplateEngineInterface::class);
```

Error Handling
--------------

[](#error-handling)

The template engine provides detailed error messages for common issues:

```
try {
    $output = $template->render('nonexistent', $data);
} catch (TemplateRenderException $e) {
    echo "Template error: " . $e->getMessage();
}
```

Custom Functions
----------------

[](#custom-functions)

Register custom functions in `config/plates.php` and call them inside templates via `$this->functionName(...)`:

```
'functions' => [
    'asset' => 'App\\Helpers\\AssetHelper::url',
    'route' => 'App\\Helpers\\RouteHelper::generate',
]
```

```
