How to set different template layout for different modules in Symfony

谁都会走 提交于 2019-12-02 20:44:52

Yes, you can define separate layouts per view (or disable the layout altogether). To do this, you must create (or edit, if you already have it) the view.yml file in the /config directory of your module. You can define the layout to be used for all views of the module or for each view separately. For example:

#in /apps/my_app/modules/my_module/config/view.yml

#this will apply custom_layout to all views of the module
all:
  layout: custom_layout

#this will apply login_layout to the loginSuccess view
loginSuccess:
  layout: login_layout

#disable layout for this view
homeSuccess:
  has_layout: false

In all cases, the layout is the file in your app's /templates directory (with .php appended). If you do not define any layout directives in the module's view configuration file, the default layout will be used.

Or if you are inside actions, you can use simply:

$this->setLayout('name_file_layout_without_extension');

And after you can work on template that you are using inside the module.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!