カスタムフィールドタイプに適切なHTMLを生成するために、カスタムフォームテーマを作成しています。twigfileを登録しましたが、奇妙な関数が見つからないというエラーを除いて、正常に動作します。
コレクションタイプを作成するデフォルトのテーマ(form_div_layout)からパーツをコピーしました。次に、デフォルトのスタイルとの干渉を避けるためにブロック名を変更しました。ブロック名を変更する前は機能し、ローカル定義も使用しますが、その後、twigはブロックを関数として使用できないようです(デフォルトのテーマでは機能しますが)。誰かが私にヒントを教えてもらえますか?
これは、デフォルトのテンプレートからコピーしただけで機能します。
{% block sortableCollection_widget %}
{% spaceless %}
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{% if form.parent is empty %}
{{ form_errors(form) }}
{% endif %}
{{ block('sortableCollection_rows') }}
{{ form_rest(form) }}
</div>
{% endspaceless %}
{% endblock %}
{% block sortableCollection_rows %}
{% spaceless %}
<ol class='.collection-editor .collection-sortable'>
{% for child in form %}
{{ form_row(child) }}
{% endfor %}
</ol>
{% endspaceless %}
{% endblock sortableCollection_rows %}
{% block form_row %}
{% spaceless %}
<li>using my template
{{ form_label(form) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
</li>
{% endspaceless %}
{% endblock form_row %}
{% block form_rows %}
{% spaceless %}
{% for child in form %}
{{ form_row(child) }}
{% endfor %}
{% endspaceless %}
{% endblock form_rows %}
ここで、form_rowの名前をsortableCollection_rowに変更すると、次のエラーが発生します。関数「sortableCollection_row」は、39行目のDTAMetadataBundle:Form:sortableCollection.html.twigに存在しません。
そして、sortableCollection_row(child)が呼び出される場所を指します。
{% block sortableCollection_widget %}
{% spaceless %}
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{% if form.parent is empty %}
{{ form_errors(form) }}
{% endif %}
{{ block('sortableCollection_rows') }}
{{ form_rest(form) }}
</div>
{% endspaceless %}
{% endblock %}
{% block sortableCollection_rows %}
{% spaceless %}
<ol class='.collection-editor .collection-sortable'>
{% for child in form %}
{{ form_row(child) }}
{% endfor %}
</ol>
{% endspaceless %}
{% endblock sortableCollection_rows %}
{% block sortableCollection_row %}
{% spaceless %}
<li>using my template
{{ form_label(form) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
</li>
{% endspaceless %}
{% endblock sortableCollection_row %}
{% block form_rows %}
{% spaceless %}
{% for child in form %}
{{ sortableCollection_row(child) }} // ERROR.
{% endfor %}
{% endspaceless %}
{% endblock form_rows %}
アイデア、誰か?ありがとう!