Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f34675

Browse files
committed
Documented custom engines and DelegatingEngine
1 parente243485 commit9f34675

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎components/templating/introduction.rst‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,41 @@ The ``Helper`` has one required method:
161161
:method:`Symfony\\Component\\Templating\\Helper\\HelperInterface::getName`.
162162
This is the name that is used to get the helper from the ``$view`` object.
163163

164+
Creating a Custom Engine
165+
------------------------
166+
167+
Besides providing a PHP templating engine, you can also create your own engine
168+
using the Templating component. To do that, create a new class which
169+
implements the:class:`Symfony\\Component\\Templating\\EngineInterface`
170+
interface. This interface requires 3 method:
171+
172+
*:method:`render($name, array $parameters = array()) <Symfony\\Component\\Templating\\EngineInterface::render>`
173+
- Renders a template
174+
*:method:`exists($name) <Symfony\\Component\\Templating\\EngineInterface::exists>`
175+
- Checks if the template exists
176+
*:method:`supports($name) <Symfony\\Component\\Templating\\EngineInterface::supports>`
177+
- Checks if the given template can be handled by this engine.
178+
179+
Using Multiple Engines
180+
----------------------
181+
182+
It is possible to use multiple engines at the same time using the
183+
:class:`Symfony\\Component\\Templating\\DelegatingEngine` class. This class
184+
takes a list of engines and acts just like a normal templating engine. The
185+
only difference is that it delegates the calls to one of the other engines. To
186+
choose which one to use for the template, the
187+
:method:`EngineInterface::supports() <Symfony\\Component\\Templating\\EngineInterface::supports>`
188+
method is used.
189+
190+
..code-block::php
191+
192+
use Acme\Templating\CustomEngine;
193+
use Symfony\Component\Templating\PhpEngine;
194+
use Symfony\Component\Templating\DelegatingEngine;
195+
196+
$templating = new DelegatingEngine(array(
197+
new PhpEngine(...),
198+
new CustomEngine(...)
199+
));
200+
164201
.. _Packagist:https://packagist.org/packages/symfony/templating

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp