Handlebars
Best practices for writing clean, logic-less Handlebars (hbs) templates.From its SKILL.md
npx -y skills add ecelayes/roots-skills --skill handlebarsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
1.8 KB, 410 tokens by cl100k_base, as published. Nobody here has run it
Handlebars Templating Standards
The "Logic-less" Philosophy
- Data Preparation: Templates should strictly DISPLAY data. All filtering, sorting, or complex math MUST happen in the application code (Controller/Service) before the data reaches the template.
- Avoid Spaghettis: If you need more than two nested
{{#if}}or{{#each}}blocks, consider refactoring the data structure or creating a custom helper.
Syntax & Helpers
- Escaping:
- Default
{{ value }}is safe and escapes HTML characters. - Use
{{{ value }}}(triple-stash) ONLY for trusted HTML strings (e.g., pre-sanitized content).
- Default
- Custom Helpers:
- Do not write complex inline logic. Instead of
{{#if (eq (mod index 2) 0)}}, create a helper{{#if (isEven index)}}or, better yet, pre-calculateisEvenin the data model. - Register helpers for formatting dates, currencies, and translation.
- Do not write complex inline logic. Instead of
Component Architecture (Partials)
- Atomic Design: Break complex UIs into small files in the
partials/directory.- Naming convention:
_card.hbs,_navbar.hbs.
- Naming convention:
- Context Passing:
- Explicit Context:
{{> myPartial specificData }}is preferred over implicit context inheritance. - Block Partials: Use
{{#> layout}} ... {{/layout}}for wrapping content (like slots).
- Explicit Context:
Troubleshooting
- Missing Properties: Handlebars fails silently on undefined properties. Ensure your data object structure strictly matches the template expectations.
- Prototypes: If using Mongoose/ORMs, convert documents to Plain Old JavaScript Objects (POJOs) (e.g.,
.lean()or.toJSON()) before passing to Handlebars to avoid prototype access issues.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.