Skip to content
flow-convert-handlebars-to-liquid logo

Convert Handlebars to Liquid.js Templates

flow-convert-handlebars-to-liquid

Convert Handlebars template syntax to Liquid.js in prompts. Use when migrating prompt templates from Flow SDK to Output SDK.

SKILL.md

Full skill instructions

Convert Handlebars to Liquid.js Templates

Overview

This skill guides the conversion of Handlebars template syntax (used in Flow SDK) to Liquid.js syntax (required by Output SDK). This is critical for prompt template migration.

When to Use This Skill

During Migration:

  • Converting prompt templates from Flow SDK
  • Fixing template syntax errors in migrated prompts
  • Setting up new prompt files with correct syntax

Error Symptoms:

  • Template conditionals not rendering
  • Variables not being interpolated
  • Syntax errors in prompt files

Syntax Conversion Reference

Variable Interpolation

HandlebarsLiquid.js
{{variable}}{{ variable }}
{{user.name}}{{ user.name }}
{{items.[0]}}{{ items[0] }}

Key Rule: Always include spaces inside braces: {{ variable }} not {{variable}}

Conditionals

HandlebarsLiquid.js
{{#if condition}}{% if condition %}
{{else}}{% else %}
{{/​if}}{% endif %}
{{#unless condition}}{% unless condition %}
{{/​unless}}{% endunless %}

Comparison Operators

HandlebarsLiquid.js
{{#if (eq a b)}}{% if a == b %}
{{#if (ne a b)}}{% if a != b %}
{{#if (gt a b)}}{% if a > b %}
{{#if (lt a b)}}{% if a < b %}
{{#if (and a b)}}{% if a and b %}
{{#if (or a b)}}{% if a or b %}

Loops

HandlebarsLiquid.js
{{#each items}}{% for item in items %}
{{this}}{{ item }}
{{@index}}{{ forloop.index0 }}
{{@first}}{{ forloop.first }}
{{@last}}{{ forloop.last }}
{{/​each}}{% endfor %}

Default Values

HandlebarsLiquid.js
{{variable}} (with default helper){{ variable | default: "fallback" }}

Comments

HandlebarsLiquid.js
{{! comment }}{% comment %} comment {% endcomment %}
{{!-- comment --}}{% comment %} comment {% endcomment %}

Common Conversion Examples

Example 1: Simple Variable

<!-- Handlebars -->
Hello, {{userName}}! Your order {{orderId}} is ready.
<!-- Liquid.js -->
Hello, {{ userName }}! Your order {{ orderId }} is ready.

Example 2: Conditional

<!-- Handlebars -->
{{#if includeDetails}}
Here are the details:
{{details}}
{{else}}
No details available.
{{/​if}}
<!-- Liquid.js -->
{% if includeDetails %}
Here are the details:
{{ details }}
{% else %}
No details available.
{% endif %}

Example 3: Nested Conditionals

<!-- Handlebars -->
{{#if isPremium}}
  Premium content:
  {{#if hasAccess}}
    {{premiumContent}}
  {{else}}
    Please upgrade to access.
  {{/​if}}
{{else}}
  Basic content: {{basicContent}}
{{/​if}}
<!-- Liquid.js -->
{% if isPremium %}
  Premium content:
  {% if hasAccess %}
    {{ premiumContent }}
  {% else %}
    Please upgrade to access.
  {% endif %}
{% else %}
  Basic content: {{ basicContent }}
{% endif %}

Example 4: Loop

<!-- Handlebars -->
Items to process:
{{#each items}}
- {{this.name}}: {{this.value}}
{{/​each}}
<!-- Liquid.js -->
Items to process:
{% for item in items %}
- {{ item.name }}: {{ item.value }}
{% endfor %}

Example 5: Loop with Index

<!-- Handlebars -->
{{#each steps}}
Step {{@index}}: {{this.description}}
{{/​each}}
<!-- Liquid.js -->
{% for step in steps %}
Step {{ forloop.index }}: {{ step.description }}
{% endfor %}

Example 6: Comparison

<!-- Handlebars -->
{{#if (eq status "active")}}
  Active user
{{else if (eq status "pending")}}
  Pending approval
{{else}}
  Inactive
{{/​if}}
<!-- Liquid.js -->
{% if status == "active" %}
  Active user
{% elsif status == "pending" %}
  Pending approval
{% else %}
  Inactive
{% endif %}

Example 7: Boolean Handling

Important: Booleans in Liquid.js templates can be tricky. Convert to strings for reliable comparisons.

// In step code, convert boolean to string
variables: {
  hasData: data ? 'yes' : 'no',
  isEnabled: enabled ? 'true' : 'false'
}
<!-- In prompt -->
{% if hasData == 'yes' %}
Data is available: {{ data }}
{% endif %}

{% if isEnabled == 'true' %}
Feature is enabled.
{% endif %}

Example 8: Default Values

<!-- Handlebars (with helper) -->
Language: {{language}}
<!-- Liquid.js -->
Language: {{ language | default: "English" }}

Complete Prompt Migration Example

Before: Handlebars Prompt

// prompts.ts
export const analyzePrompt = `
You are an AI assistant.

{{#if systemContext}}
Context: {{systemContext}}
{{/​if}}

User Query: {{query}}

{{#if examples}}
Examples:
{{#each examples}}
{{@index}}. Input: {{this.input}}
   Output: {{this.output}}
{{/​each}}
{{/​if}}

{{#if (eq mode "detailed")}}
Provide a detailed analysis with explanations.
{{else if (eq mode "brief")}}
Provide a brief summary.
{{else}}
Provide a standard response.
{{/​if}}
`;

After: Liquid.js Prompt File

---
provider: openai
model: gpt-4o
temperature: 0.5
---

<system>
You are an AI assistant.

{% if systemContext %}
Context: {{ systemContext }}
{% endif %}
</​system>

<user>
User Query: {{ query }}

{% if examples %}
Examples:
{% for example in examples %}
{{ forloop.index }}. Input: {{ example.input }}
   Output: {{ example.output }}
{% endfor %}
{% endif %}

{% if mode == "detailed" %}
Provide a detailed analysis with explanations.
{% elsif mode == "brief" %}
Provide a brief summary.
{% else %}
Provide a standard response.
{% endif %}
</​user>

Finding Handlebars Syntax

Search for patterns that need conversion:

# Find Handlebars conditionals
grep -r "{{#if" src/​workflows/
grep -r "{{/​if}}" src/​workflows/
grep -r "{{#each" src/​workflows/
grep -r "{{#unless" src/​workflows/

# Find variables without spaces
grep -r "{{[^#/!]" src/​workflows/ | grep -v "{{ "

Verification Checklist

  • All {{#if ...}} converted to {% if ... %}
  • All {{/​if}} converted to {% endif %}
  • All {{#each ...}} converted to {% for ... in ... %}
  • All {{/​each}} converted to {% endfor %}
  • All {{else}} converted to {% else %}
  • All variables have spaces: {{ var }} not {{var}}
  • Boolean variables converted to strings for comparison
  • Comparison operators use ==, !=, >, <
  • Loop variables use forloop.index instead of @index

Related Skills

  • flow-convert-prompts-to-files - Full prompt conversion
  • flow-analyze-prompts - Identifying prompts to convert
  • flow-validation-checklist - Migration validation

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View