What is the best place for a template that can be used in multiple apps? [closed]

点点圈 提交于 2019-12-23 01:43:08

问题


I have 2 apps in my Symfony framework: backend and frontend.

is it possible to have templates that are being used by both apps?

And if so, what is the best place to put those template?


回答1:


The only way I've been able to overcome this in the past has been to create a plugin for the shared pieces.

IE: Create a folder under plugins called

TemplatesPlugin

Within that, create a modules folder, and within that, create a regular module folder structure.

Example of a template path:

sf_root/plugins/TemplatesPlugin/modules/book/pageSuccess.php
sf_root/plugins/TemplatesPlugin/modules/book/_title.php

Ensure the plugin is enabled in config/ProjectConfiguration.class.php (if you are using enableAllPluginsExcept it will be, otherwise you need to add it into the plugins array that should already be there).

You can then access these templates as any other templates, for example:

include_partial('book/title', array('title'=>'hello'));

Whilst this feels a bit of a hack, it works pretty well.




回答2:


There is even a simpler way than using a plugin: Have a look at this post.

He is just extending the application configuration in apps/appName/config/appNameConfigurations.class.php:

class appNameConfiguration extends sfApplicationConfiguration {

  public function configure() {
    sfConfig::set('sf_app_template_dir', sfConfig::get('sf_root_dir') . '/templates');
  }

}

This approach looks cleaner to me. I just don't know if it extends the path where symfony looks for templates or just sets it.




回答3:


I'm not yet Symfony expert (I've already read "The Definitive Guide to symfony"), so I can make a mistake.

There is no mentions in official documentation about common templates for different applications. The most appropriate directory for common templates within single application is apps/templates/.

Maybe someone knows the answer. It will be interesting to read. Good luck.



来源:https://stackoverflow.com/questions/1865572/what-is-the-best-place-for-a-template-that-can-be-used-in-multiple-apps

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