Skip to content

Instantly share code, notes, and snippets.

@sreynen
Last active August 29, 2015 14:25
Show Gist options
  • Save sreynen/3ee9eeb4e9157532e00a to your computer and use it in GitHub Desktop.
Save sreynen/3ee9eeb4e9157532e00a to your computer and use it in GitHub Desktop.
How to use SimpleThingsFormExtraBundle HelpExtension in Silex

1

This goes in your app.php, after you register FormServiceProvider:

$app['form.type.extensions'] = $app->share($app->extend('form.type.extensions', function ($extensions) use ($app) {
    $extensions[] = new SimpleThings\FormExtraBundle\Form\Extension\FieldTypeHelpExtension();
    return $extensions;
}));

2

Then make your own form layout Twig, extending whatever you were using before (in this example, bootstrap_3_layout.html.twig):

{% use "bootstrap_3_layout.html.twig" %}

{% block field_help %}
    {% if help is defined %}
        <span class="help">{{ help }}</span>
    {% endif %}
{% endblock %}

{% block form_row %}
{% spaceless %}
    <div>
        {{ form_label(form, label|default(null)) }}
        {{ form_errors(form) }}
        {{ form_widget(form) }}
        {{ block('field_help') }}
    </div>
{% endspaceless %}
{% endblock form_row %}

Note: this is copied from SimpleThings/FormExtraBundle/Resources/views/Form/field_type_help.html.twig with field_row changed to form_row

3

Then load this layout in your form Twig, with something like this at the top:

{% form_theme form 'custom_layout.twig' %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment