ioleo
ioleo

Reputation: 4817

Symfony2: Form fragment themeing and TWIG

Can anyone explain why this code:

{% form_theme form _self %}

{% block avo_gallery_upload_widget %}
{% spaceless %}
    <label for="name">Name:</label>
    {{ form_widget(form.name) }}
    <label for="description">Description:</label>
    {{ form_widget(form.description) }}
{% endspaceless %}
{% endblock avo_gallery_upload_widget %}

Throws

Method "name" for object "Symfony\Component\Form\FormView" does not exist in MyBundle:Default:upload.html.twig at line 13 

For reference: line 13 is {{ form_widget(form.name) }}

But when wrapped in IF clause:

{% form_theme form _self %}

{% block avo_gallery_upload_widget %}
{% spaceless %}
{% if form.name is defined %}
    <label for="name">Name:</label>
    {{ form_widget(form.name) }}
    <label for="description">Description:</label>
    {{ form_widget(form.description) }}
{% endif %}
{% endspaceless %}
{% endblock avo_gallery_upload_widget %}

Suddenly everything works fine!

For reference - this is how form looks like:

class GalleryUploadType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('name', 'text')
            ->add('description', 'textarea')
          ;
    }

    public function getName()
    {
        return 'avo_gallery_upload';
    }

    public function getDefaultOptions(array $options){
        return array('data_class' => 'Me\MyBundle\Entity\GalleryUpload');
    }
}

Upvotes: 1

Views: 1297

Answers (1)

ioleo
ioleo

Reputation: 4817

fabpot closed github issue (2012-07-03) with comment:

Every month, I spend hours trying to reproduce the problem without luck. So, I'm giving up for now as there is probably something else going on in your application (as it works fine for almost everyone). If you have any new information that can be relevant, feel free to reopen a new ticket. Thanks.

Since it probably is something wrong in my application and there is nothing new I could add to the question I am closeing this question.

If you happen to encounter this error have a look at this workaround.

If you have any additional info on reproducing the problem, post it here.

Upvotes: 1

Related Questions