Skip to content

Commit dd051ea

Browse files
committed
updte templating docs
1 parent b491e64 commit dd051ea

File tree

1 file changed

+87
-4
lines changed

1 file changed

+87
-4
lines changed

docs/framework/templating.md

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,83 @@ By default the Antidot framework doesn't have any template engine, you can insta
66

77
Choose a template engine from the different available implementations
88

9+
## PUG Template Renderer
10+
11+
Use [PHP Pug as Template engine](https://github.com/pug-php/pug)
12+
913
> [Pug Template renderer](https://github.com/antidot-framework/phug-template-renderer)
1014
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+
1162
## Config
1263

1364
<!-- tabs:start -->
1465

1566
### **Symfony Style yaml**
1667

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+
```
1886
1987
### **Symfony php**
2088
@@ -31,7 +99,7 @@ $config = [
3199
'template' => [
32100
'pretty' => true,
33101
'expressionLanguage' => 'js',
34-
'pugjs' => false,ee
102+
'pugjs' => false,
35103
'localsJsonFile' => false,
36104
'cache' => 'var/cache/pug',
37105
'template_path' => 'templates/',
@@ -49,7 +117,23 @@ $config = [
49117

50118
### **Zend style yaml**
51119

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+
```
53137
54138
### **Zend Style php**
55139
@@ -82,4 +166,3 @@ $config = [
82166

83167
<!-- tabs:end -->
84168

85-
## Usage

0 commit comments

Comments
 (0)