File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,38 @@ syntax:
71
71
You cannot drop the ``Action `` part of the method name when using the
72
72
single colon notation.
73
73
74
+ Embedding your controller in a template
75
+ ---------------------------------------
76
+
77
+ If you want to embed your controller in a template, you need to use the
78
+ following syntax:
79
+
80
+ .. configuration-block ::
81
+
82
+ .. code-block :: html+twig
83
+
84
+ {# app/Resources/views/base.html.twig #}
85
+
86
+ {# ... #}
87
+ <div id="sidebar">
88
+ {{ render(controller(
89
+ 'AppBundle\C ontroller\H elloController:indexAction',
90
+ )) }}
91
+ </div>
92
+
93
+ .. code-block :: html+php
94
+
95
+ <!-- app/Resources/views/base.html.php -->
96
+
97
+ <!-- ... -->
98
+ <div id="sidebar">
99
+ <?php echo $view['actions']->render(
100
+ new \S ymfony\C omponent\H ttpKernel\C ontroller\C ontrollerReference(
101
+ 'AppBundle\C ontroller\H elloController:indexAction'
102
+ )
103
+ ) ?>
104
+ </div>
105
+
74
106
.. _controller-service-invoke :
75
107
76
108
Invokable Controllers
Original file line number Diff line number Diff line change @@ -98,4 +98,36 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
98
98
) ?>
99
99
</div>
100
100
101
+ If your controller should be used as a service, you can reference it like that
102
+ instead:
103
+
104
+ .. configuration-block ::
105
+
106
+ .. code-block :: html+twig
107
+
108
+ {# app/Resources/views/base.html.twig #}
109
+
110
+ {# ... #}
111
+ <div id="sidebar">
112
+ {{ render(controller(
113
+ 'AppBundle\C ontroller\A rticleController:recentArticlesAction',
114
+ { 'max': 3 }
115
+ )) }}
116
+ </div>
117
+
118
+ .. code-block :: html+php
119
+
120
+ <!-- app/Resources/views/base.html.php -->
121
+
122
+ <!-- ... -->
123
+ <div id="sidebar">
124
+ <?php echo $view['actions']->render(
125
+ new \S ymfony\C omponent\H ttpKernel\C ontroller\C ontrollerReference(
126
+ 'AppBundle\C ontroller\A rticleController:recentArticlesAction',
127
+ array('max' => 3)
128
+ )
129
+ ) ?>
130
+ </div>
131
+
132
+
101
133
The result of an embedded controler can also be :doc: `cached </http_cache/esi >`
You can’t perform that action at this time.
0 commit comments