Fixes #96 - Better documentation for includes/partials

This commit is contained in:
Patrick Steele-Idem 2015-07-06 10:19:02 -06:00
parent 6de11ddc9f
commit 84fc5d915b

View File

@ -686,12 +686,43 @@ For example, both of the following are valid and equivalent:
## Includes
Other Marko files can be included using the `<include>` tag and a relative path. For example:
Marko supports includes/partials. Other Marko files can be included using the `<include>` tag and a relative path. For example:
```xml
<include template="./greeting.marko" name="Frank" count="30"/>
```
The value of the `template` attribute can also be a dynamic JavaScript expression that resolves to a loaded template as shown below:
In your controller:
```javascript
var myIncludeTarget = require('./my-include-target.marko');
var anotherIncludeTarget = require('./another-include-target.marko');
template.render({
myIncludeTarget: myIncludeTarget,
anotherIncludeTarget: anotherIncludeTarget
},
...);
```
And then in your template:
```xml
<include template="${data.myIncludeTarget}" name="Frank" count="30"/>
<include template="${data.anotherIncludeTarget}" name="Frank" count="30"/>
```
You can also choose to load the include target within the calling template as shown below:
```xml
<require module="./my-include-target.marko" var="myIncludeTarget" />
...
<include template="${data.myIncludeTarget}" name="Frank" count="30"/>
```
## Variables
Input data passed to a template is made available using a special `data` variable. It's possible to declare your own variables as shown in the following sample code: