PHPackages                             quellabs/canvas-twig - 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-twig

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

quellabs/canvas-twig
====================

Twig template engine integration for the Canvas PHP framework

1.0.3(1mo ago)03MITPHP

Since Jul 23Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (10)Versions (5)Used By (0)

Twig Template Engine for Canvas Framework
=========================================

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

A Twig 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
- **Flexible Configuration**: Supports all major Twig configuration options
- **Caching Support**: Built-in template caching with cache management
- **Global Variables**: Support for framework-wide template variables
- **Custom Extensions**: Easy registration of custom functions and filters
- **String Templates**: Render templates from strings as well as files
- **Multiple Template Paths**: Support for namespaced template directories
- **Debug Mode**: Development-friendly debugging and auto-reload features

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

[](#installation)

Install the package via Composer:

```
composer require quellabs/canvas-twig
```

The package includes Twig as a dependency and automatically copies the configuration file to `/config/twig.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/twig.php` during installation.

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

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

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

```
'template_engine' => 'twig',
```

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

```
/**
 * @Route("/")
 * @return Response
 */
public function index(Request $request): Response {
    return $this->render('pages/home.twig', [
        '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('twig')->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.twig', $data);
} catch (TemplateRenderException $e) {
    echo "Template error: " . $e->getMessage();
}
```

Performance Considerations
--------------------------

[](#performance-considerations)

1. **Enable Caching**: Always enable caching in production environments
2. **Template Compilation**: Twig compiles templates to PHP for better performance
3. **Auto-reload**: Disable `auto_reload` in production to avoid file system checks
4. **Cache Warming**: Consider pre-compiling templates for optimal performance

Debugging
---------

[](#debugging)

Enable debug mode during development:

```
$config = [
    'debugging' => true,
    'auto_reload' => true,
    'strict_variables' => true  // Catch undefined variable errors
];
```

Use the debug function in templates:

```
{{ dump(variable) }}
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Canvas Framework with TemplateEngineInterface

License
-------

[](#license)

MIT License

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Submit a pull request

Support
-------

[](#support)

For issues specific to this Twig implementation, please check:

1. Twig documentation:
2. Canvas framework documentation
3. This implementation's source code comments

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance89

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Total

4

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57e4ab872b3e37536367f2d26b192df3d3bb6a6a1cebec9a104d14a6d2ffe157?d=identicon)[noescom](/maintainers/noescom)

---

Top Contributors

[![quellabs](https://avatars.githubusercontent.com/u/7067695?v=4)](https://github.com/quellabs "quellabs (1 commits)")

---

Tags

Twig templatecanvas-frameworktemplate-integrationphp-templating

### Embed Badge

![Health badge](/badges/quellabs-canvas-twig/health.svg)

```
[![Health](https://phpackages.com/badges/quellabs-canvas-twig/health.svg)](https://phpackages.com/packages/quellabs-canvas-twig)
```

###  Alternatives

[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M53](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M161](/packages/symfony-ux-twig-component)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[symfony/ux-live-component

Live components for Symfony

1635.6M71](/packages/symfony-ux-live-component)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
