Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)

Handlebars Helpers Reference

Handlebars-style block helpers for control flow and context management in Scryber templates.


On this page

Overview

Handlebars helpers provide familiar syntax for common template patterns like iteration, conditionals, and context switching. They compile to native Scryber XML elements at parse time.


Block Helpers

These helpers use {{#helper}}...{{/helper}} syntax to wrap content.

Helper Description Special Variables
{{#each}} Iterate over arrays and collections @index, @first, @last
{{#with}} Switch data context to a specific object this, ../
{{#if}} Conditional rendering based on expressions -

Branch Helpers

These helpers work within block helpers to create conditional branches.

Helper Description Used With
{{else if}} Alternative condition branch {{#if}}
Fallback branch when conditions are false {{#if}}, {{#each}}, {{#with}}

Utility Helpers

Helper Description Usage
Debug output to console/trace {{log model.value level="debug"}}

Common Patterns

Iteration with Conditionals

{{#each model.items}}
  <div class="item {{if(@first, 'first', '')}}">
    {{#if this.isActive}}
      <span class="active">{{this.name}}</span>
    {{else}}
      <span class="inactive">{{this.name}}</span>
    {{/if}}
  </div>
{{/each}}

Context Switching with Parent Access

{{#with model.order}}
  <h2>Order #{{orderNumber}}</h2>

  {{#each items}}
    <div>{{this.name}} - Order #{{../orderNumber}}</div>
  {{/each}}
{{/with}}

Multiple Conditions

{{#if model.score >= 90}}
  <span class="grade-a">Excellent</span>
{{else if model.score >= 80}}
  <span class="grade-b">Good</span>
{{else if model.score >= 70}}
  <span class="grade-c">Average</span>
{{else}}
  <span class="grade-f">Needs Improvement</span>
{{/if}}

See Also