How to override the default template when using Symfony Forms, Twig and SymfonyTwigBridge?

I use Symfony and Twig in a Silex application.

I have a registration page with a form in:

{% extends "base.twig" %}

{% block title %}Welcome to My Example site{% endblock %}
{% block head %}
{{ parent() }}
{% endblock %}
{% block content %}

<div class="row">
<div class="span12">
    <h2>Register</h2>
    <p>
        Register for this site and we'll give you free access to cool stuff
        in addition you can subscribe to our premium content.
    </p>

    <form  action="{{app.config.site.secureUrl}}/register-handler" method="post">
        <fieldset >
            {{ form_widget(form) }}
            <button type="submit" class="btn btn-info">Send</button>
        </fieldset>
    </form>
</div>
</div>

</div>

{% endblock %}

When I try to display the page, I get the following error:

Twig_Error_Syntax: filter "trans" does not exist in "form_div_layout.html.twig" on line 35

I narrowed this down to a Symfony translation extension extension that is not installed, and as such the default template located at:

vendor\symfony\twigbridge\Symfony\Bridge\Twig\Resources\views\Form\form_div_layout.html.twig

not displayed correctly.

I created a new template based on the above without translation functions.

Question

How can I get a branch to use the new template instead of the standard one?

+3
source share
2 answers

, Twig:

$app->register(new Silex\Provider\TwigServiceProvider(), array(
      'twig.path' => __DIR__ . '/[Path_to_views_directory]',
      'twig.class_path' => __DIR__ . '/vendor/twig/lib',
      'twig.form.templates'   => array([path_to_your_overriden_template]),
 )) ;

. : TwigProvider

, :

$app->register(new Silex\Provider\TranslationServiceProvider(), array(
      'locale' => '[Your_locale]',
      'translation.class_path' =>  __DIR__ . '/../vendor/symfony/src',
      'translator.messages' => array()
)) ;

, :

, .

+6

All Articles