Blame view

vendor/wyrihaximus/twig-view/quickstart.md 1.5 KB
c4650843   Etienne Pallier   Ajout du dossier ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
## Change AppView
```PHP
// src/View/AppView.php
namespace App\View;

use WyriHaximus\TwigView\View\TwigView;

class AppView extends TwigView
{
     // Code ...
}
```

## Load Helpers
```PHP
// src/View/AppView.php
namespace App\View;

use WyriHaximus\TwigView\View\TwigView;

class AppView extends TwigView
{
    public function initialize()
    {
        $this->loadHelper('Html');
        $this->loadHelper('Form');
    }
```

Note: TwigView will look for its templates with the extension `.twig` and then for `.tpl` (deprecated).

## Create the default layout to be used by TwigView named `default.twig` instead of `default.ctp`
Layout example
```Twig
<!DOCTYPE html>
<html>
<head>
    {{ Html.charset()|raw }}
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>
        {{ __('MySite') }}
        {{ _view.fetch('title')|raw }}
    </title>
    {{ Html.meta('icon')|raw }}

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

    {{ _view.fetch('meta')|raw }}
    {{ _view.fetch('css')|raw }}
    {{ _view.fetch('script')|raw }}
</head>
<body>

    <header>
        {{ _view.fetch('header')|raw }}
    </header>

    <section>
        <h1 class="page-title">{{ _view.fetch('title') }}</h1>
        {{ _view.fetch('content')|raw }}
    </section>

</body>
```

## Create a view template
in Template/Controller/action.twig
```Twig

{{ _view.start('header') }}
    <p>It's my header</p>
{{ _view.end() }}

{{ _view.assign('title', "it's my title") }}

<p>It's my content</p>
```