From fcedbd0ba20c9489bdc2ad18c4f1be9904a188c1 Mon Sep 17 00:00:00 2001 From: Brian Lim Date: Fri, 19 May 2017 14:32:50 -0400 Subject: [PATCH 1/2] Partial Clarification --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 9b6ffb7a3..0d5ff11c8 100644 --- a/README.md +++ b/README.md @@ -493,6 +493,40 @@ 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 as expected with other view rendering engines. + +In other words, `Contexts` are currently not supported. + +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`. + +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. From 5955ad191e5de7f95a6fb124d1d5a4fad46923e3 Mon Sep 17 00:00:00 2001 From: Brian Lim Date: Thu, 1 Jun 2017 18:04:07 -0400 Subject: [PATCH 2/2] Additional clarification with example --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0d5ff11c8..e7a9c1ab8 100644 --- a/README.md +++ b/README.md @@ -497,9 +497,7 @@ Mustache.render(template, view, { The wording above with regard to partials "thought of as a single, expanded template", is exact. -That is, partial view data is not nested as expected with other view rendering engines. - -In other words, `Contexts` are currently not supported. +That is, partial view data is not nested nor is there a way to specify `Context`. For example, @@ -523,7 +521,11 @@ 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`. +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.