1
嘗試定製Symfony2的形式生成HTML代碼看起來像下面的例子時:故障排除「變量‘值’不存在」定製text_widget
<div class="cform_box">
<div><label>First name:</label></div>
<input name="" type="text" id="" class="TextBox" />
</div>
<div class="cform_box" style="height:auto">
<div><label>Message:</label></div>
<textarea name="" rows="10" cols="38" id="" class="TextBox" style="height:100px;" /></textarea>
</div>
我的表單代碼:
$builder->add('name', 'text', array('label' =>'First Name:'));
$builder->add('message', 'textarea', array('label' =>'Message:'));
的模板contact.html.twig
:
{% form_theme form _self %}
{% block text_widget %}
{% spaceless %}
<input type="text" class='TextBox' {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{% endblock %}
{% block textarea_widget %}
{% spaceless %}
<div class="textarea_widget">
<textarea rows="10" cols="38" id="{{ id }}" class="TextBox" style="height:100px;">{{ value }}</textarea>
</div>
{% endspaceless %}
{% endblock textarea_widget %}
<div class="cform_box">
<div>{{ form_label(form.name) }}</div>{{ form_widget(form.name) }}
</div>
<div class="cform_box" style="height:auto">
<div>{{ form_label(form.message) }}</div>{{ form_widget(form.message) }}
</div>
我得到Variable "value" does not exist in contact.html.twig
或Variable "id" does not exist in form_div_layout.html.twig
如果我評論{% block text_widget %}
了。
我使用的Symfony 2.0.15
感謝了很多,做了什麼,我想那! – Leo