Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Rendering Clarification - Documentation, Question #635

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Expand Up @@ -493,6 +493,42 @@ Mustache.render(template, view, {
});
```

#### Note on Partials - No Context Support (Yet!)

The wording above with regard to partials "thought of as a single, expanded template", is exact.

That is, partial view data is not nested nor is there a way to specify `Context`.

For example,

```
var view = {
name: 'test name 1',
names: [
{ name: 'test name 2' },
{ name: 'test name 3' }
],
partial: {
names: [
{ name: 'test name 4' },
{ name: 'test name 5' }
]
}
};

var template = '{{#names}}Hi, {{name}}!{{/names}} PARTIAL TEST : {{> partial}}'
var partial = '{{#names}}Hello, my name is {{name}}.{{/names}}'
console.log(Mustache.render(template, view, { partial: partial}));
```

does not output the expected `test name 4` or `test name 5`. The output is actually

```
Hi, test name 2!Hi, test name 3! PARTIAL TEST : Hello, my name is test name 2.Hello, my name is test name 3.
```

Therefore, the JSON object must be flat / flattened when using partials with no key conflicts.

### Custom Delimiters

Custom delimiters can be used in place of `{{` and `}}` by setting the new values in JavaScript or in templates.
Expand Down