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

Custom delimiters do not work in nested partials #738

Closed
aielo opened this issue Feb 24, 2020 · 1 comment
Closed

Custom delimiters do not work in nested partials #738

aielo opened this issue Feb 24, 2020 · 1 comment

Comments

@aielo
Copy link
Contributor

aielo commented Feb 24, 2020

Custom delimiters only work in the template itself and its (level 1) partials (thanks to #679). For inner partials (level 2+), however, default tags are used rather than the custom ones provided in render.

This behavior can be reproduced with the sample code:

const Mustache = require("mustache");
const tags = ["[[", "]]"];
const partials = {};

for (let l = 1; l <= 5; l++) {
  partials["level" + l] = `partial level ${l}\n`;
  if (l < 5) {
    partials["level" + l] += `${tags[0]}> level${l + 1} ${tags[1]}`;
  }
}

const output = Mustache.render(
  `template\n${tags[0]}> level1 ${tags[1]}`,
  {}, partials, tags
);

console.log(output);

Double brackets are set as custom tags in const tags = ["[[", "]]"], and it outputs:

template       
partial level 1
partial level 2
[[> level3 ]]

[[> level1 ]] in template and [[> level2 ]] in the first level partial are properly resolved, while the first inner partial [[> level3 ]] is left unresolved.

Switching to const tags = ["[[{{", "}}]]"], and keeping the curly brackets within custom delimiters, it outputs:

template
partial level 1      
partial level 2      
[[partial level 3    
  [[partial level 4  
    [[partial level 5
]]]]]]

Here, custom tags are again used in template and first level partial. Default Mustache tags are then used in inner partials, rendering them wrongly.

Overriding Mustache.tags works normally. Changing the sample code:

...
Mustache.tags = ["[[", "]]"];
const tags = Mustache.tags; // just to generate test partials
...
const output = Mustache.render(
  `template\n${tags[0]}> level1 ${tags[1]}`,
  {}, partials // no custom tags
);
...

Output is the expected:

template       
partial level 1
partial level 2
partial level 3
partial level 4
partial level 5
aielo added a commit to aielo/mustache.js that referenced this issue Feb 25, 2020
aielo added a commit to aielo/mustache.js that referenced this issue Feb 25, 2020
aielo added a commit to aielo/mustache.js that referenced this issue Feb 25, 2020
@aielo aielo changed the title Custom delimiters do not work in inner partials Custom delimiters do not work in nested partials Feb 25, 2020
@phillipj
Copy link
Collaborator

Very sorry for the late response, been more busy than usual lately.

Thanks a bunch for the very elaborate description of what you've stumbled onto and steps to reproduce, much appreciated 👍

aielo added a commit to aielo/serverless-enhanced-config that referenced this issue Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants