Skip to content

Commit a63a255

Browse files
committed
add doc for twig phptypes
1 parent dc0b77f commit a63a255

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

languages/twig/index.rst

+56-3
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ PhpTypes
189189

190190
.. code-block:: html+jinja
191191

192-
{% variable_name \Foo\Bar %}
192+
{# variable_name \Foo\Bar #}
193193
{{ variable_name.method.subMethod }}
194194

195195
* ``goto`` - Class name or method
196196
* ``complete`` - class name or method with twig shortcut name and inside class name inside comment
197-
198-
Possible Scopes
197+
198+
Possible Variables Scopes
199199

200200
.. code-block:: html+jinja
201201

@@ -213,4 +213,57 @@ Possible Scopes
213213
{% extends ... %}
214214
{# variable_name \Foo\Bar #}
215215

216+
Variable parser support controller as source, just definite it in root tree of twig file eg under extends tag
217+
218+
.. code-block:: html+jinja
219+
220+
{# @controller FooBundle:Bar:index #}
221+
{# @Controller FooBundle:BarFood:index #}
222+
223+
Controller also detect on twig path
224+
225+
.. code-block:: html+jinja
226+
227+
// FooBundle/Resources/views/BarFood/index.html.twig
228+
// FooBundle\BarFoodController\indexAction
229+
230+
Valid template variable detection in controller method
231+
232+
.. code-block:: php
233+
234+
return $this->render('foo...', array(
235+
'form' => $editForm->createView(),
236+
));
237+
238+
// and all other template render calls ...
239+
return $this->renderView('foo...', array(
240+
'form' => $editForm->createView(),
241+
));
242+
243+
$foo = array(
244+
'form' => $editForm->createView();
245+
);
246+
247+
$foo['form'] = $editForm->createView();
248+
249+
return $foo;
250+
return $this->render('foo...', $foo);
251+
252+
Array values
253+
254+
.. code-block:: html+jinja
255+
256+
{# entities \Foo\Bar[]
257+
{% for entity in entities %}
258+
{{ entity.completeMe }}
259+
{% endfor %}
260+
261+
Whitelist for variable pattern
262+
263+
.. code-block:: html+jinja
264+
265+
{{ "entity" }}
266+
{% for entity in "entities" %}
267+
{% if "entity" > "entity" %}
268+
{% set var = "entity" %}
216269

0 commit comments

Comments
 (0)