Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Mustache=require('mustache')
- // Пример использования:
- const template = `
- --- Standard section (should NOT be affected) ---
- {{#isAdmin}}
- Welcome Admin!
- {{/isAdmin}}
- {{^isUser}}
- Please log in.
- {{/isUser}}
- --- Our new section with {{+array}} and {{-array}} ---
- {{+users}}
- Total users: {{users.length}}
- {{#users}}
- Hello, {{name}}!
- {{/users}}
- {{-users}}
- {{+products}}
- No products available.
- {{-products}}
- {{+emptyArray}}
- This should not be seen.
- {{-emptyArray}}
- --- Example with standard section that LOOKS similar ---
- {{+users}}
- This is INSIDE the length check.
- {{-users}}
- --- Example that WON'T work without {{+}} and {{-}} ---
- {{#users}} // This is a standard section. It will not be replaced.
- This is a standard {{#users}} section.
- {{/users}} // This is a standard {{/users}} section.
- `;
- const data = {
- users: [
- { name: "Alice" },
- { name: "Bob" }
- ],
- products: [],
- emptyArray: [],
- isAdmin: true,
- isUser: false
- };
- // --- Выполнение рендеринга ---
- const html = Mustache.render(template, data);
- console.log(html);
Advertisement
Add Comment
Please, Sign In to add comment