2011-08-22 52 views
2

我實際上正在開發一個自定義表單字段類型,它擴展了file表單字段類型。關於這方面的documentation尚未寫入。如何設置使用自定義表單字段類型呈現的模板?

我已經創建了我的自定義字段&註冊它像服務。

自定義表單字段類型:

class CustomFileType extends AbstractType 
{ 
    public function getParent(array $options) 
    { 
     return 'file'; 
    } 

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

服務:

<service id="form.type.custom_file" class="Namespace\CustomFileType"> 
    <tag name="form.type" alias="custom_file" /> 
</service> 

我可以用它像一個文件中的字段,但我不知道我怎麼可以設置將與被呈現模板我的自定義字段。

回答

1

在模板渲染的形式,可以包括這樣的:

{% form_theme form _self %} 

{% block custom_file_widget %} 
    {# rendering of the widget goes here #} 
{% endblock %} 

檢查form_div_layout.html.twig文件的方式,你就會明白的基本機制。

+0

非常感謝!精彩的工作:) – egeloen

相關問題