PHPackages                             wyrihaximus/twig-view - 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. wyrihaximus/twig-view

ActiveCakephp-plugin[Templating &amp; Views](/categories/templating)

wyrihaximus/twig-view
=====================

Twig powered View for CakePHP

5.0.1(6y ago)804.7M—0.2%291MITPHPPHP ^7.2

Since Jun 9Pushed 1mo ago25 watchersCompare

[ Source](https://github.com/cakephp/legacy-twig-view)[ Packagist](https://packagist.org/packages/wyrihaximus/twig-view)[ RSS](/packages/wyrihaximus-twig-view/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (36)Used By (1)

TwigView plugin for CakePHP
===========================

[](#twigview-plugin-for-cakephp)

[![Build Status](https://github.com/cakephp/legacy-twig-view/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/cakephp/legacy-twig-view/actions/workflows/ci.yml/badge.svg?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/9a21d0d72ae6382eedb3274bb46c51941f7f09ec4a2231b8ec20942e7a68215a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f63616b657068702f6c65676163792d747769672d766965773f736f72743d73656d766572267374796c653d666c61742d737175617265)](https://packagist.org/packages/wyrihaximus/twig-view)[![Total Downloads](https://camo.githubusercontent.com/f5aa56da3f558593d6b428ab1cbbf5a6ab2f7024859e62b44fbc53398309064c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77797269686178696d75732f747769672d766965773f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wyrihaximus/twig-view/stats)[![Code Coverage](https://camo.githubusercontent.com/57a936c614d68b324b6b4750bf5f3ada9f29186fd321650f791f5184c2202eb2/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f63616b657068702f6c65676163792d747769672d766965772f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/cakephp/legacy-twig-view?branch=master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This plugin allows you to use the [Twig Templating Language](http://twig.sensiolabs.org) for your views.

In addition to enabling the use of most of Twig's features, the plugin is tightly integrated with the CakePHP view renderer giving you full access to helpers, objects and elements.

DEPRECATED: Use [cakephp/twig-view](https://github.com/cakephp/twig-view) instead.

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

[](#installation)

To install via [Composer](https://getcomposer.org/), use the command below.

```
composer require wyrihaximus/twig-view
```

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

[](#configuration)

### Load Plugin

[](#load-plugin)

Run the following CLI command:

```
bin/cake plugin load WyriHaximus/TwigView
```

### Use View class

[](#use-view-class)

Instead of extending from the `View` let `AppView` extend `TwigView`:

```
namespace App\View;

use WyriHaximus\TwigView\View\TwigView;

class AppView extends TwigView
{
}
```

Quick Start
-----------

[](#quick-start)

TwigView will look for its templates with the extension `.twig`.

### Layout

[](#layout)

Replace `templates/layout/default.php` by this `templates/layout/default.twig`

```

    {{ Html.charset()|raw }}

        {{ __('myTwigExample') }}
        {{ _view.fetch('title')|raw }}

    {{ Html.meta('icon')|raw }}

    {{ Html.css('default.app.css')|raw }}
    {{ Html.script('app')|raw }}

    {{ _view.fetch('meta')|raw }}
    {{ _view.fetch('css')|raw }}
    {{ _view.fetch('script')|raw }}

        {{ _view.fetch('header')|raw }}

    {{ Flash.render()|raw }}

        {{ _view.fetch('title')|raw }}

        {{ _view.fetch('content')|raw }}

        {{ _view.fetch('footer')|raw }}

```

### Template View

[](#template-view)

Create a template, for example `templates/Users/index.twig` like this

```
{{ _view.assign('title', __("I'm title")) }}

{{ _view.start('header') }}
    I'm header
{{ _view.end() }}

{{ _view.start('footer') }}
    I'm footer
{{ _view.end() }}

I'm content
```

Usage
-----

[](#usage)

### Use `$this`

[](#use-this)

With twig `$this` is replaced by `_view`

For example, without using Twig writing

```
