Skip to content

Twig render problem with form use name "time" in FormType #13590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewsmm opened this issue Feb 4, 2015 · 2 comments
Closed

Twig render problem with form use name "time" in FormType #13590

andrewsmm opened this issue Feb 4, 2015 · 2 comments

Comments

@andrewsmm
Copy link

I use twig in Symfony 2.6.5. I created a FormType and set in public function getName(){ return "time" }
and get next error when render form(form):
Variable "widget" does not exist in form_div_layout.html.twig at line 123

{% block time_widget -%}
    {% if widget == 'single_text' %}
        {{- block('form_widget_simple') -}}
    {% else -%}
        {% set vars = widget == 'text' ? { 'attr': { 'size': 1 }} : {} %}
        <div {{ block('widget_container_attributes') }}>
            {{ form_widget(form.hour, vars) }}{% if with_minutes %}:{{ form_widget(form.minute, vars) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second, vars) }}{% endif %}
        </div>
    {%- endif %}
{%- endblock time_widget %}

If i use any other name this problem resolve.

@jakzal
Copy link
Contributor

jakzal commented Feb 4, 2015

This happens because the time name is already taken by the TimeType. As mentioned in the documentation:

note that the getName() method should return a unique identifier for this form "type"

In other words, choose a different name for your form. Using a prefix for your form names will make it less likely you'll get a name clash.

@jakzal jakzal closed this as completed Feb 4, 2015
@andrewsmm
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants