<!---
# This file is part of the ChillDev ProxyTemplating bundle.
#
# @author Rafał Wrzeszcz <rafal.wrzeszcz@wrzasq.pl>
# @copyright 2013 © by Rafał Wrzeszcz - Wrzasq.pl.
# @version 0.0.1
# @since 0.0.1
# @package ChillDev\Bundle\ProxyTemplatingBundle
-->

# About this project

This project is a Symfony2 bundle, that provides proxy templating engine that translates templates references.

## Templating engine

In the world of **Symfony 2** most people use [Twig](http://twig.sensiolabs.org/) as templating engine. However we, at [Chillout Development](http://chilldev.pl/) can't understand that and [prefer good old PHP over Twig](http://wrzasq.pl/blog/chilldevviewhelpersbundle-php-templating-helpers-for-symfony-2.html). That's why default views for our bundles are provided in *PHP*. We came across this problem, when working on [ChillDevFileManagerBundle](https://github.com/chilloutdevelopment/ChillDevFileManagerBundle) and wanted to use `@Template` annotation while still allowing user which templating engine he wants to use in his system. Many vendor bundles enforce use of particular templating engine (which make them useless for systems using different ones) or implement templating switch by-hand in each controller action, which is a bit tedious work.

To simplify code structure in our bundles we use `@Template` annotation from [SensioFrameworkExtraBundle](https://github.com/sensio/SensioFrameworkExtraBundle). It allows us to drop any direct template references from controller code. But there is one problem with this annotation - while it drops template reference from code it makes that implicit reference quite costant. Mainly it makes it impossible to switch between templating engines (if controller uses *Twig* and your application *PHP* templates you are doomed). *DelegatingEngine* from Symfony does not help here, since it just delegates templating to subsequent engine based on it's name, which is in our case already hardcoded.

Since `@Template` annotation is very handy and we didn't want to stop using it, while still having possiblity to switch between templating engines we created different kind of delegating engine - one that doesn't rely on template name, but on configuration and we called it `ProxyEngine`.

Thanks to that, when creating actions with this engine we can do:

```php
    /**
     * @Template(engine="default")
     */
    public function fooAction()
    {
        // action code here
        return $viewData;
    }
```

In this example annotation will still generate constant template reference to `Bundle:Controller:foo.html.default` and delegation will be done in rendering time. Depending on configuration it can for example forward rendering to `Bundle:Controller:foo.html.php` or `Bundle:Controller:foo.html.twig`.

## Performance

Ok, to state it clear - we did not perform any performance tests. Just basing on own thoughts we don't think using this proxy can generate much impact. Of course there is a problem with re-calling templating service (which is usually `DelegatingEngine`), but `ProxyEngine` calls it with already parsed template reference so there is no need for parsing any new template references.
