Guest User

Untitled

a guest
Aug 23rd, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. let Mustache=require('mustache')
  2. // Пример использования:
  3. const template = `
  4. --- Standard section (should NOT be affected) ---
  5. {{#isAdmin}}
  6. Welcome Admin!
  7. {{/isAdmin}}
  8.  
  9. {{^isUser}}
  10. Please log in.
  11. {{/isUser}}
  12.  
  13. --- Our new section with {{+array}} and {{-array}} ---
  14. {{+users}}
  15. Total users: {{users.length}}
  16. {{#users}}
  17. Hello, {{name}}!
  18. {{/users}}
  19. {{-users}}
  20.  
  21. {{+products}}
  22. No products available.
  23. {{-products}}
  24.  
  25. {{+emptyArray}}
  26. This should not be seen.
  27. {{-emptyArray}}
  28.  
  29. --- Example with standard section that LOOKS similar ---
  30. {{+users}}
  31. This is INSIDE the length check.
  32. {{-users}}
  33.  
  34. --- Example that WON'T work without {{+}} and {{-}} ---
  35. {{#users}} // This is a standard section. It will not be replaced.
  36. This is a standard {{#users}} section.
  37. {{/users}} // This is a standard {{/users}} section.
  38. `;
  39.  
  40. const data = {
  41. users: [
  42. { name: "Alice" },
  43. { name: "Bob" }
  44. ],
  45. products: [],
  46. emptyArray: [],
  47. isAdmin: true,
  48. isUser: false
  49. };
  50.  
  51. // --- Выполнение рендеринга ---
  52. const html = Mustache.render(template, data);
  53. console.log(html);
  54.  
Advertisement
Add Comment
Please, Sign In to add comment