2016-11-14 100 views
0

根據這一http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_templates.html覆蓋在自己的捆綁FosUserBundle模板,而不是應用程序/資源

我可以覆蓋應用程序/資源目錄FOSUserBundle模板或創建一個子包。

有沒有辦法將這些模板放入我自己的bundle目錄中?

我試着加入:

twig: 
    debug:   "%kernel.debug%" 
    strict_variables: "%kernel.debug%" 
    paths: 
     '%kernel.root_dir%/../src/AppBundle/Resources/FOSUserBundle/views/': FOSUSerBundle 

我config.yml

回答

0

沒有,模板名稱的FOSUserBundle的控制器內部硬編碼的,因此你不能將它們放在自己的包。 (除非你完全覆蓋所有控制器)

0

不,你不能。模板名稱在fosub控制器中進行硬編碼。但是, 作爲解決方法,您可以將自己的模板包含在重寫的模板中。對於樣品,像這樣做:

// app/Resources/FOSUserBundle/views/layout.html.twig 
{% include '@YourBundleName/layout.html.twig' %} 
0

我在項目symfony2.3版本開發的一個做模板壓倒一切的FosUserBundle。 請嘗試以下代碼,可以幫助你

config.yml

twig: 
    debug:   "%kernel.debug%" 
    strict_variables: "%kernel.debug%" 

FrontBundle /控制器/ LoginController.php

<?php 
namespace Dhi\UserBundle\Controller; 

use FOS\UserBundle\Controller\SecurityController as Controller; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\Security\Core\SecurityContextInterface; 
use Symfony\Component\Security\Core\Exception\AuthenticationException; 
use Symfony\Component\HttpFoundation\RedirectResponse; 

class LoginController extends Controller 
{ 
    protected function loginController(array $data) 
    { 
     $request = $this->get('request'); 
     return $this->render('FrontBundle:login:login.html.twig'); 
    } 
} 

FrontBundle /資源/視圖/登錄/ login.html.twig

{% extends "DhiUserBundle::layout.html.twig" %} 
{% trans_default_domain 'FOSUserBundle' %} 
{% block body %} 
    {% block fos_user_content %} 

     {% trans_default_domain 'FOSUserBundle' %} 

     // Your login form code here 

    {% endblock fos_user_content %} 
{% endblock body %} 
0

你可以看看你的FOSUser和Symfony的版本和閱讀此線程:https://github.com/FriendsOfSymfony/FOSUserBundle/issues/2439

我已經經歷這個錯誤,這並沒有讓我重寫FOS模板,因爲它們使用的(在最新的2.0版本。 0-beta)名稱空間語法(帶@符號的語法)來鏈接模板。 http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html

+0

在答案中包含更多詳細信息,並避免僅提供一些外部鏈接。 – Masoud

+0

我做到了,它更好嗎? – NoTra

+0

您對字符數沒有任何限制。爲什麼不復制和粘貼(包括一些編輯,以避免太多可以壓倒性的內容)並仍然有這些引用。現在的方式,如果這些鏈接發生任何事情,你的答案將是無用的。 – Masoud

0

今天我有同樣的問題:和的緣故吧,Symfony的的2.7.23版本之前,您無法通過把命名的文件就在同一個文件夾,這裏描述的覆蓋模板。我config.yml文件如下:

# Twig Configuration 
twig: 
    debug: '%kernel.debug%' 
    strict_variables: '%kernel.debug%' 
    paths: 
     "%kernel.root_dir%/../src/WebBundle/Resources/views/user/": FOSUser 

我添加了所有FOSUserBundle模板下WebBundle /資源/視圖/用戶/並提出了一些擴展/包括所有模板的變化和現在的作品。