Respect/Template — Issue #10: View Layer
Author: alganet
Created: 2011-12-15 10:14:17+00:00
State: open

We currently implement a template engine, this is awesome. But now we're starting to mix up layers.

A controller should never do something like:

```php
return array(
'body > h1' => $author->name
);
```

'Cause "body > h1" is particular from the View layer, not the Controller one. We currently have nothing to offer to an user that wants to separate those, and we need to encourage this good practice.

I've thought on a simple aliasing mechanism on the template:

```php
$template = new Html('hi.html');
$template->alias("body > h1", "page_title");
```

Respect\Template would try to match an alias before matching a selector. Or perhaps it should match only aliases, forcing the developer to register them and separate the logic.

Is possible (perhaps on Respect\Framework =D) to use a Config-compatible INI to register those aliases, making it easy for the developer to add new ones:

```
[products Respect\Template\Html]
file = 'products.html'
alias[] = ["body > h1", "page_title"]
alias[] = ["#cart", "products"]
```

Another possible syntax (my favourite):

```php
$template = new Html('hi.html');
$template->aliasFor["body > h1"] = "page_title";
```

```
[products Respect\Template\Html]
file = 'products.html'
aliasFor[body > h1] = page_title
aliasFor["#cart"] = products
```