如何在 Symfony 中为不同的模块设置不同的模板布局 [英] How to set different template layout for different modules in Symfony

查看:20
本文介绍了如何在 Symfony 中为不同的模块设置不同的模板布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Symfony 中为不同的模块设置不同的模板布局?

How to set different template layouts for different modules in Symfony?

我有一个银行应用程序,它由一个登录屏幕和一个成员部分组成.因此,当用户访问我的网站时,他将看到一个登录屏幕.登录后,他将被重定向到会员部分,他可以在那里进行任何银行业务.

I have a banking application that consists of a login screen, and a member section. So when a user goes to my site he will be presented with a login screen. After login in he will be redirected to the member section that he can do his whatever banking needs.

那么,如何为登录界面和会员版块内的页面设置不同的布局?Symfony 似乎使用 frontend/templates/layout.php 作为所有页面的模板.是否可以定义不同的布局?

So, how to set different layouts for the login screen and the pages inside the member section? Symfony seems to use frontend/templates/layout.php as the template for ALL pages. Is it possible to define different layouts?

推荐答案

是的,您可以为每个视图定义单独的布局(或完全禁用布局).为此,您必须在模块的/config 目录中创建(或编辑,如果您已经拥有)view.yml 文件.您可以定义要用于模块的所有视图或单独用于每个视图的布局.例如:

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

在所有情况下,布局是应用程序的/templates 目录中的文件(附加 .php).如果您没有在模块的视图配置文件中定义任何布局指令,则将使用默认布局.

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.

这篇关于如何在 Symfony 中为不同的模块设置不同的模板布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆