2016-11-17 43 views
0

我有一個名爲VendorDeliveryBundle的第三方包。Symfony包繼承和樹枝模板覆蓋

我要重寫它的枝條模板,我這句法在我的應用程序模板,嫩枝一個叫一個:
{% include '@VendorDelivery/Frontend/Booking/_delivery.html.twig' with { 'form': form } only %} 喜歡這個工作,供應商模板被調用。

但是如果我想通過註冊在AppKernel壓倒一切的束(如在https://symfony.com/doc/2.8/bundles/inheritance.html描述的),並通過創建覆蓋此模板: App/DeliveryBundle/Resources/views/Frontend/Booking/_delivery.html.twig 此模板不會覆蓋供應商模板。

但是,如果我使用此語法代替 {% include 'VendorDeliveryBundle:Frontend:Booking/_delivery.html.twig' with { 'form': form } only %} 該模板被覆蓋。

似乎@語法不能按預期工作。

所以我不知道它是否是一個錯誤或正常行爲考慮這個symfony的文檔https://symfony.com/doc/2.8/bundles/inheritance.html

資源壓倒一切的,只有當你是指資源與@ FOSUserBundle工作/資源/配置/路由/ security.xml方法。如果您在不使用@BundleName快捷方式的情況下引用資源,則不能使用這種方式重寫它們。

感謝,

回答

2

@在樹枝語法是一個名爲 「命名空間路徑」 功能。 (documentation

使用{% include 'Bundle:Folder:template' %}的功能它與{% include '@Bundle\Folder\template' %}不一樣。

爲樣本,如果你重寫fosub包:

{% include '@FOSUser/Security/login.html.twig' %} {# Will be fosub template #} 
{% include '@User/Security/login.html.twig' %} {# Will be overrided template #} 
{% include 'FOSUserBundle:Security:login.html.twig' %} {# Also will be overrided template #} 

另外,我想補充一點,如果你想覆蓋只有一個模板(沒有全局的功能控制器,監聽器等),你可以添加模板到你的應用程序目錄。這在documentation