handlebars
When to Use
Use this skill when:
- Creating or modifying
.hbstemplate files - Adding new Handlebars helpers or partials
- Debugging template rendering issues
- Understanding existing template patterns in Aurora CLI
- Working with dynamic code generation
Critical Patterns
Aurora CLI Template Engine Setup
The template engine is configured in src/@cliter/utils/template-engine.ts:
- Uses
handlebarslibrary withhandlebars-helpersaddon (189+ built-in helpers) - Custom helpers are registered in
src/@cliter/handlebars/helpers/ - Partials are registered in
src/@cliter/handlebars/partials/ - Templates are in
src/templates/(back/, front/, pipeline/)
Important: Aurora CLI includes ALL helpers from the handlebars-helpers package automatically. These 189+ helpers are available in every template without any additional configuration.
Helper Registration Pattern
// src/@cliter/handlebars/helpers/my-helper.ts
import * as handlebars from 'handlebars';
handlebars.registerHelper('myHelper', function(param1: string, param2: any, options)
{
// options.data.root contains all template data
// options.fn(this) executes block content
// options.inverse(this) executes else block
return result;
});
Partial Registration Pattern
// src/@cliter/handlebars/partials/my-partial.ts
import * as handlebars from 'handlebars';
handlebars.registerPartial('myPartial', `
{{#each items}}
{{ this.name }}
{{/each}}
`);
Handlebars Syntax Guide
Basic Expressions
Whitespace Control
Block Helpers
content if true
content if false
- - -
content if false
Custom Block Helpers (Aurora CLI)
content if equal
content if not equal
Aurora CLI Helper Categories
String Transformation Helpers
| Helper | Description | Example |
|---|---|---|
toCamelCase |
Convert to camelCase | {{ toCamelCase "my_name" }} → myName |
toPascalCase |
Convert to PascalCase | {{ toPascalCase "my_name" }} → MyName |
toKebabCase |
Convert to kebab-case | {{ toKebabCase "myName" }} → my-name |
toSnakeCase |
Convert to snake_case | {{ toSnakeCase "myName" }} → my_name |
sumStrings |
Concatenate strings | {{ sumStrings "Hello" " " "World" }} |
singleLine |
Remove line breaks | {{ singleLine multiLineText }} |
Variable Management Helpers
Array/Object Helpers
has items
Conditional Helpers
is undefined
not in array
Property Filter Helpers
Most property helpers filter schema.aggregateProperties:
:
Import Manager Helper
ID Generation Helpers
Handlebars-Helpers Package (Built-in)
Aurora CLI includes all 189+ helpers from the handlebars-helpers package. These are available automatically in all templates.
String Helpers (36 helpers)
is string
Array Helpers (28 helpers)
found
is array
has 5
at
Comparison Helpers (24 helpers)
both truthy
at least one truthy
falsey
equal
loosely equal
not equal
greater than
greater or equal
less than
less or equal
comparison
found
matches
even
odd
every 2nd
truthy
falsey
both falsey
not equal
not greater
not less
Math Helpers (16 helpers)
Number Helpers (9 helpers)
Object Helpers (14 helpers)
has key
is object
:
:
URL Helpers (9 helpers)
Date Helpers (3 helpers)
Path Helpers (8 helpers)
Collection Helpers (2 helpers)
empty
Inflection Helpers (2 helpers)
Regex Helpers (2 helpers)
matches
HTML Helpers (7 helpers)
Markdown Helpers (2 helpers)
Misc Helpers (5 helpers)
Logging Helpers (11 helpers)
Full Reference: See references/handlebars-helpers-reference.md for complete documentation.
Decision Tree
Need string transformation? → toCamelCase, toPascalCase, toKebabCase, toSnakeCase (Aurora)
→ camelcase, pascalcase, snakecase, dashcase (handlebars-helpers)
Need to store temporary data? → setVar
Need to build arrays/objects? → array, object, push
Need conditional rendering? → if, unless, eq, unlessEq, ternary, and, or, not, compare
Need to iterate? → each, loops, forEach, eachIndex, forIn, forOwn
Need to filter properties? → get*Properties helpers (Aurora custom)
Need to manage imports? → importManager with importsArray
Need unique IDs? → uuid, nanoid
Need math operations? → add, subtract, multiply, divide, ceil, floor, round
Need string manipulation? → trim, split, replace, truncate, append, prepend
Need array operations? → first, last, sort, unique, filter, map, join
Need object access? → get, hasOwn, forIn, forOwn
Need URL handling? → encodeURI, decodeURI, urlParse, stripQuerystring
Need path operations? → basename, dirname, extname, resolve
Code Examples
Example 1: Creating a New Helper
// src/@cliter/handlebars/helpers/is-required-property.ts
import * as handlebars from 'handlebars';
import { Property } from '../../types';
handlebars.registerHelper('isRequiredProperty', function(
property: Property,
)
{
return !property.nullable && !property.hasOwnProperty('defaultValue');
});
Example 2: Using Multiple Helpers in Template
export interface Input
{
?: ;
}
Example 3: Complex Import Management
Example 4: Conditional Blocks with Context
// Handle enum type
// Handle other types
Commands
# Build after adding helpers
yarn build
# Find all helpers
ls src/@cliter/handlebars/helpers/
# Find helper usage in templates
grep -r "helperName" src/templates/
# Test template rendering
yarn test
Common Mistakes to Avoid
-
Missing whitespace control: Use
~to trim unwanted whitespacecontent content -
Wrong context access: Use
../to access parent context in loops -
Forgetting to register helper: Add import in
src/@cliter/handlebars/helpers/index.ts -
Using
{{instead of{{{: For HTML/code output, use triple braces to avoid escaping
Resources
- Templates: See assets/ for helper and partial templates
- Aurora Helpers: See references/helpers-reference.md for Aurora CLI custom helpers
- Built-in Helpers: See references/handlebars-helpers-reference.md for handlebars-helpers package
- GitHub: https://github.com/helpers/handlebars-helpers