mogoman
mogoman

Reputation: 2298

Symfony 2 theming a textarea widget

I am having some trouble theming a textarea.

I have created a separate theme file with the following themes:

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

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

The first block theme works (text_widget), but the second causes the page not to load at all. It works if I change the block line to

        {{ block('field_widget') }}

but then twig renders a normal text field. According to https://github.com/symfony/symfony/tree/master/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form I should be able to use textarea_widget.

Any ideas?

Upvotes: 2

Views: 4998

Answers (3)

webda2l
webda2l

Reputation: 6708

{% block textarea_widget %}
{% spaceless %}
    <div class="textarea_widget">
        <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
    </div>
{% endspaceless %}
{% endblock textarea_widget %}

no?

Upvotes: 8

mogoman
mogoman

Reputation: 2298

Here is one way of doing it:

{% block textarea_widget %}
    <div class="textarea_widget">
        <textarea>{{ value }}</textarea>
    </div>
{% endblock %}

However this doesn't render the widget's attributes (class name etc), but I can live with that.

Upvotes: 0

greg0ire
greg0ire

Reputation: 23255

Recursion alert! You're calling the block inside himself! Didn't Twig detect recursion? If not, you could probably create a feature request for getting an error message...

Upvotes: 0

Related Questions