tags:

views:

108

answers:

3

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?

A: 

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.

Alex
What you say is correct, there is no official doc on this issue, that's why I am asking it here, cause I don't know a correct answer for this issue.the apps/templates/ contains the global templates for that particular app. What I am looking for is a possibility to use templates across different apps...
Kennethvr
Unfortunately, I've not encourtered with such task, so I can't help you. Sorry.
Alex
+2  A: 

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.

benlumley
I noticed that the name of the files in the module in the plugin needs to be unique. (example) If book already exists in your project and you create it in the plugins, it will try to search the page first in the existing module book (located in the backend or frontend) and then in the plugin folder. If you want to be sure that no conflicts are happening, use unique module names in the plugins also.
Gerbrand
Yes, good point. It can also be a powerful feature too - it allows you to over-ride a single template from a plugin without having to duplicate the whole plugin in your app, or edit the plugins files.
benlumley
+1  A: 

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.

Felix Kling
Good find. Like this more than my method. Even if its changing rather than adding to the path, I'm sure that can be changed. The approach is what I like.
benlumley
Having looked at using this, it replaces the template dir under apps/appname/templates with an alternative, rather than adding an extra one as the plugin does. And can't see a way to achieve this other than using a plugin. So for me at least, it feels like a bad solution.
benlumley