@@ -48,3 +48,81 @@ $twig->loadExtension(new CustomExtension();
4848// Inject:
4949$renderer = new TwigRenderer($twig);
5050```
51+
52+ ## Included extensions and functions
53+
54+ The included Twig extension adds support for url generation. The extension is
55+ automatically activated if the [ UrlHelper] ( ../helpers/url-helper.md ) and
56+ [ ServerUrlHelper] ( ../helpers/server-url-helper.md ) are registered with the
57+ container.
58+
59+ The following template functions are exposed:
60+
61+ - `` path `` : Render the relative path for a given route and parameters. If there
62+ is no route, it returns the current path.
63+
64+ ``` twig
65+ {{ path('article_show', {'id': '3'}) }}
66+ Generates: /article/3
67+ ```
68+
69+ - `` url `` : Render the absolute url for a given route and parameters. If there is
70+ no route, it returns the current url.
71+
72+ ``` twig
73+ {{ url('article_show', {'slug': 'article.slug'}) }}
74+ Generates: http://example.com/article/article.slug
75+ ```
76+
77+ - `` absolute_url `` : Render the absolute url from a given path. If the path is
78+ empty, it returns the current url.
79+
80+ ``` twig
81+ {{ absolute_url('path/to/something') }}
82+ Generates: http://example.com/path/to/something
83+ ```
84+
85+ - `` asset `` Render an (optionally versioned) asset url.
86+
87+ ``` twig
88+ {{ asset('path/to/asset/name.ext', version=3) }}
89+ Generates: path/to/asset/name.ext?v=3
90+ ```
91+
92+ To get the absolute url for an asset:
93+
94+ ``` twig
95+ {{ absolute_url(asset('path/to/asset/name.ext', version=3)) }}
96+ Generates: http://example.com/path/to/asset/name.ext?v=3
97+ ```
98+
99+ ## Configuration
100+
101+ The following details configuration specific to Twig, as consumed by the
102+ ` TwigRendererFactory ` :
103+
104+ ``` php
105+ return [
106+ 'templates' => [
107+ 'extension' => 'file extension used by templates; defaults to html.twig',
108+ 'paths' => [
109+ // namespace / path pairs
110+ //
111+ // Numeric namespaces imply the default/main namespace. Paths may be
112+ // strings or arrays of string paths to associate with the namespace.
113+ ],
114+ ],
115+ 'twig' => [
116+ 'cache_dir' => 'path to cached templates',
117+ 'assets_url' => 'base URL for assets',
118+ 'assets_version' => 'base version for assets',
119+ 'extensions' => [
120+ // extension service names or instances
121+ ],
122+ 'globals' => [
123+ // Global variables passed to twig templates
124+ 'ga_tracking' => 'UA-XXXXX-X'
125+ ],
126+ ],
127+ ];
128+ ```
0 commit comments