Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions components/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,25 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
$vendorTwigBridgeDir.'/Resources/views/Form',
)));
$formEngine = new TwigRendererEngine(array($defaultFormTheme));
$formEngine->setEnvironment($twig);
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
TwigRenderer::class => function () use ($formEngine, $csrfManager) {
return new TwigRenderer($formEngine, $csrfManager);
},
)));

// ... (see the previous CSRF Protection section for more information)

// add the FormExtension to Twig
$twig->addExtension(
new FormExtension(new TwigRenderer($formEngine, $csrfManager))
);
$twig->addExtension(new FormExtension());

// create your form factory as normal
$formFactory = Forms::createFormFactoryBuilder()
// ...
->getFormFactory();

.. versionadded:: 1.30
The ``Twig_FactoryRuntimeLoader`` was introduced in Twig 1.30.

The exact details of your `Twig Configuration`_ will vary, but the goal is
always to add the :class:`Symfony\\Bridge\\Twig\\Extension\\FormExtension`
to Twig, which gives you access to the Twig functions for rendering forms.
Expand Down