开发者

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

As it currently stands, this question is not a good fit for ou开发者_JAVA技巧r Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜