ractivejs/ractive — pull request #1192 by evs-chris (2014-09-09 20:06:01+00:00)
Title: Dynamic partial switching by expression

This was a TODO in the partial handling code and it scratches an itch that I've had for a while. I'm not sure this is the way this should be done, or if it was decided that it shouldn't be done. It does allow for some neat behavior though, and it has been requested a few times. #1096

#### Pros

* Can display lists of items with a different template for different classes of item using a property of the item `{{#items}}{{>.type}}{{/}}`
* Can add content on the fly without replacing existing partials - see example
* Can now have `-` in partial names using `{{>'hello-dashes'}}` #1165
* Any expression that resolves to a string can be used
* ???
* Profit

#### Cons

* Preference is given to existing partials for simple references, so names may overlap in slightly suprising ways. The workaround would be to always use an expression `{{>'' + commonName}}` in areas where there may be overlap.
* Can't add support for partials with `-` without using a string as above

#### Not sure?

* Expressions must resolve to a string that points to an existing partial. I think it would be neat to be able to return template (pre-parsed, string, or function) from the data, but that would probably be a pretty esoteric feature that violated separation of concerns badly.

### What it does

With this patch, if the partial is a simple reference `ref` and there exists a partial `partials[ref]`, then the existing partial is used. Else if it is a simple reference and there exists script id `ref`, then the script partial is used. Else if the value `val` of the reference or expression is found in `partials` or as a script id, then that is used. Else an empty fragment is used.

If the value of the expression changes, then the partial fragment is switched out.

### Example

```html

```