0

I'm very new to Symfony 2. I'm trying to add some other custom form fields.

The bundle I'm using has been made this way:

src/TheClient/
`-- Bundle
    |-- MyBundle
    |   |-- Controller
    |   |-- DependencyInjection
    |   |-- Entity
    |   |-- Form
    |   |-- Repository
    |   |-- Resources
    |   `-- Tests
    `-- OtherNotImportantBundle
        |-- Command
        |-- Controller
        |-- DependencyInjection
        |-- Entity
        |-- Resources
        |-- Services
        `-- Tests

I've created the file src/TheClient/Bundle/MyBundle/Resources/views/Form/fields.html.twig where there is some code like this:

{% block form_row %}
    <div class="control-group">
        {{ form_label(form) }}
        {{ form_errors(form) }}
        {{ form_widget(form) }}
    </div>
{% endblock %}

{% block text_widget %}
    <div class="text_widget controls">
        {% set type = type|default('text') %}
        {{ block('form_widget_simple') }}
    </div>
{% endblock %}

To make it short, it overrides the original form ressource to enclose it with div's. Now, what I'm supposed to do is just edit app/config/config.yml and precise the new form fields like this:

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%
    globals:
      sso_host: %sso_host%
      root_url: %root_url%
    form:
        resources:
            - 'TheClientMyBundle:Form:fields.html.twig'
#            - 'MyBundle:Form:fields.html.twig'

I've tried both solutions and they dont work, I get an error 500. I'm very new to Symfony 2. What are the steps, where should I look, to make it work?

I forgot to precise: I'm trying to follow this tutoriel from the Symfony website itself.

Thank you very much

1
  • It's a bit weird having a path like this src/Client/Bundle/MyBundle, you should have something looking like src/Client/MyBundle Commented Jan 23, 2013 at 12:43

1 Answer 1

1

What is error message? "Unable to find template..."?

Resource name should be MyBundleName:Form:fields.html.twig

where MyBundleName is name of you bundle added inside AppKernel.php file

For example Symfony\Bundle\FrameworkBundle\FrameworkBundle() bundle name is FrameworkBundle.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry I wanted to remove my question because I've solved it. In the fields.html.twig file there's a use of the function humanize which is only available in the 2.1 and... guess what the client gave me the 2.0 version (the version I'm supposed to work on) and in-between they've upgraded to 2.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.