@@ -6,15 +6,83 @@ By default the Antidot framework doesn't have any template engine, you can insta
6
6
7
7
Choose a template engine from the different available implementations
8
8
9
+ ## PUG Template Renderer
10
+
11
+ Use [ PHP Pug as Template engine] ( https://github.com/pug-php/pug )
12
+
9
13
> [ Pug Template renderer] ( https://github.com/antidot-framework/phug-template-renderer )
10
14
15
+ ## Twig Template Renderer
16
+
17
+ Coming soon.
18
+
19
+ Use [ Twig as Template engine] ( https://twig.symfony.com/ )
20
+
21
+ > [ Twig Template renderer] ( https://github.com/antidot-framework/twig-template-renderer )
22
+
23
+ ## Usage
24
+
25
+ Inject ` Antidot\Render\TemplateRenderer ` interface in your request handler constructor, then render given template with given parameters.
26
+
27
+ ``` php
28
+ <?php
29
+
30
+ declare(strict_types=1);
31
+
32
+ use Antidot\Render\TemplateRenderer;
33
+ use Laminas\Diactoros\Response\HtmlResponse;
34
+ use Psr\Http\Message\ResponseInterface;
35
+ use Psr\Http\Message\ServerRequestInterface;
36
+ use Psr\Http\Server\RequestHandlerInterface;
37
+
38
+ class SomeRequestHandler implements RequestHandlerInterface
39
+ {
40
+ private TemplateRenderer $template;
41
+
42
+ public function __construct(TemplateRenderer $template)
43
+ {
44
+ $this->template = $template;
45
+ }
46
+
47
+ public function handle(ServerRequestInterface $request): ResponseInterface
48
+ {
49
+ return new HtmlResponse(
50
+ // template is in templates/app/index.html.{pug,twig}, depending on template renderer implementation used.
51
+ $this->template->render('app/index.html', [
52
+ 'foo' => 'bar',
53
+ 'bar' => [1, 2, 3],
54
+ ])
55
+ );
56
+ }
57
+ }
58
+
59
+
60
+ ```
61
+
11
62
## Config
12
63
13
64
<!-- tabs:start -->
14
65
15
66
### ** Symfony Style yaml**
16
67
17
- Coming soon
68
+ ``` yaml
69
+ parameters :
70
+ templates :
71
+ extension : pug # pug|twig
72
+ template :
73
+ pretty : true # only pug
74
+ expressionLanguage : js # only pug
75
+ pugjs : false # only pug
76
+ localsJsonFile : false # only pug
77
+ cache : var/cache/pug
78
+ template_path : templates/
79
+ globals :
80
+ title : Antidot Framework
81
+ filters : []
82
+ keywords : []
83
+ helpers : []
84
+ default_params : => []
85
+ ` ` `
18
86
19
87
### **Symfony php**
20
88
@@ -31,7 +99,7 @@ $config = [
31
99
' template' => [
32
100
' pretty' => true,
33
101
' expressionLanguage' => 'js',
34
- 'pugjs' => false,ee
102
+ ' pugjs' => false,
35
103
' localsJsonFile' => false,
36
104
' cache' => 'var/cache/pug',
37
105
' template_path' => 'templates/',
@@ -49,7 +117,23 @@ $config = [
49
117
50
118
### ** Zend style yaml**
51
119
52
- Coming soon
120
+ ``` yaml
121
+ templates :
122
+ extension : pug
123
+ template :
124
+ pretty : true
125
+ expressionLanguage : js
126
+ pugjs : false
127
+ localsJsonFile : false
128
+ cache : var/cache/pug
129
+ template_path : templates/
130
+ globals :
131
+ title : Antidot Framework
132
+ filters : []
133
+ keywords : []
134
+ helpers : []
135
+ default_params : => []
136
+ ` ` `
53
137
54
138
### **Zend Style php**
55
139
@@ -82,4 +166,3 @@ $config = [
82
166
83
167
<!-- tabs:end -->
84
168
85
- ## Usage
0 commit comments