简体   繁体   English

更改Symfony2中的模板/视图位置

[英]Change templates/views location in Symfony2

I will be working on project that has different theme for each domain (same application will be serving multiple domains). 我将研究每个域具有不同主题的项目(相同的应用程序将服务于多个域)。

  1. I need to change location of templates completely outside the application folder, possible on another volume 我需要完全在应用程序文件夹之外更改模板的位置,可能在另一个卷上
  2. I need to make it work with multiple domains with multiple themes - i guess theres cache problem 我需要使其与具有多个主题的多个域一起使用-我猜那里存在缓存问题

S how to do this stuff with Symfony2 and twig? 用Symfony2和树枝如何做这些东西?

EDIT: I will try to ask this: What or where do I need to rewrite to get custom logic on locating specific templates that symfony uses to render pages. 编辑:我将尝试问这个问题:在查找symfony用于呈现页面的特定模板时,需要重写什么或在何处获取自定义逻辑。

I can't say if first point of your question is a bad practice (and don't know even if it possible, but I would say yes). 我不能说您问题的第一点是否是不好的做法(即使有可能也不知道,但我会说是)。

However, what I would do is some kind of "manager" that will takes responsibility for choosing what kind of template render, based onto your own logic. 但是,我要做的是某种“管理器”,它将负责根据您自己的逻辑选择哪种模板渲染。 Some kind of "intermediate level" between actions and views. 动作和视图之间的某种“中间级别”。

You could create it as a service and use everywhere, without have need to instantiate it every time. 您可以将其创建为服务并在任何地方使用,而无需每次都实例化它。
It could read a file for configuration or, even (but less springy), use a class-internal configuration. 它可以读取文件以进行配置,甚至可以(但不太灵活)使用类内部配置。

Algorithm could be something like this: 算法可能是这样的:

  • Take into account your request 考虑您的要求
  • "Eat" data and "spit out" the correct template (name) “吃”数据并“吐出”正确的模板(名称)
  • Pass template (name) to your view 将模板(名称)传递到视图
  • Extend (dinamically) the template given by your manager 扩展(通常)您的经理提供的模板

Please, don't ask me some code because it could result in some hundred lines :) 请不要问我一些代码,因为它可能导致几百行:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM