{"id":15659239,"url":"https://github.com/jonschlinkert/liquid-to-handlebars","last_synced_at":"2025-05-05T17:38:31.372Z","repository":{"id":16139365,"uuid":"18884741","full_name":"jonschlinkert/liquid-to-handlebars","owner":"jonschlinkert","description":"Convert liquid templates to handlebars templates! ","archived":false,"fork":false,"pushed_at":"2019-11-20T03:59:00.000Z","size":4228,"stargazers_count":22,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-29T02:41:57.027Z","etag":null,"topics":["blog","convert","filters","handlebars","helpers","liquid","tags","templates"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-17T16:08:23.000Z","updated_at":"2025-01-02T07:09:07.000Z","dependencies_parsed_at":"2022-09-02T21:02:32.784Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/liquid-to-handlebars","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fliquid-to-handlebars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fliquid-to-handlebars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fliquid-to-handlebars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fliquid-to-handlebars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/liquid-to-handlebars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252543889,"owners_count":21765238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blog","convert","filters","handlebars","helpers","liquid","tags","templates"],"created_at":"2024-10-03T13:15:52.891Z","updated_at":"2025-05-05T17:38:31.352Z","avatar_url":"https://github.com/jonschlinkert.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# liquid-to-handlebars [![NPM version](https://img.shields.io/npm/v/liquid-to-handlebars.svg?style=flat)](https://www.npmjs.com/package/liquid-to-handlebars) [![NPM monthly downloads](https://img.shields.io/npm/dm/liquid-to-handlebars.svg?style=flat)](https://npmjs.org/package/liquid-to-handlebars) [![NPM total downloads](https://img.shields.io/npm/dt/liquid-to-handlebars.svg?style=flat)](https://npmjs.org/package/liquid-to-handlebars) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/liquid-to-handlebars.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/liquid-to-handlebars)\n\n\u003e Convert liquid templates to handlebars templates.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n- [Install](#install)\n- [Why use this?](#why-use-this)\n- [Usage](#usage)\n- [Migration debugging](#migration-debugging)\n  * [Step 1: Add starter helpers](#step-1-add-starter-helpers)\n  * [Step 2: Run handlebars](#step-2-run-handlebars)\n- [Conversion Examples](#conversion-examples)\n  * [Conditionals](#conditionals)\n  * [Arrays](#arrays)\n  * [Filters](#filters)\n- [What is this?](#what-is-this)\n- [About](#about)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save liquid-to-handlebars\n```\n\n## Why use this?\n\nIf you've ever seen a jekyll boilerplate, or another project that uses [liquid](https://github.com/Shopify/liquid) templates and wished it was written in [handlebars](http://www.handlebarsjs.com/), this is your solution!\n\n* 100% of the tags mentioned in the [shopify liquid documentation](http://shopify.github.io/liquid/) convert to handlebars syntax\n* easily migrate any liquid theme or boilerplate\n* use more powerful and flexible handlebars helpers instead of liquid filters\n\n**Please [create an issue](../../issues/new) if you find a tag that doesn't convert correctly, and I'll add support. Thanks!**\n\n## Usage\n\n```js\nconst converter = require('liquid-to-handlebars');\n// Converts this liquid\nconsole.log(converter.convert('Price: ${{ product_price | default: 2.99 }}'));\n// To this handlebars\n//=\u003e 'Price: ${{default product_price 2.99}}'\n```\n\nYou will also need to include any missing handlebars helpers that provide similar functionality to the liquid filters that are being replaced. For example:\n\n```js\nconst handlebars = require('handlebars');\nhandlebars.registerHelper('default', function(a, b) {\n  return a || b || '';\n});\n\nconst fn = handlebars.compile('Price: ${{default product_price 2.99}}');\nconsole.log(fn());\n//=\u003e 'Price: $2.99'\n\nconsole.log(fn({default_price: '4.99'}));\n//=\u003e 'Price: $4.99'\n```\n\n## Migration debugging\n\n_Once your liquid templates are converted to handlebars, if you attempt to render all of the templates with handlebars without any additional work, it's a good bet that you'll receive a bunch of errors from missing helpers._\n\nSave yourself a bunch of time and frustration by following these steps:\n\n### Step 1: Add starter helpers\n\nAdd the following to your app:\n\n```js\nconst handlebars = require('handlebars');\n\n// override handlebars' built-in `helperMissing` helper, so that we \n// can easily see which helpers are missing and get them fixed\nhandlebars.registerHelper('helperMissing', function() {\n  const opts = [].slice.call(arguments).pop();\n  console.log(`missing helper {{${opts.name}}}`);\n});\n```\n\n### Step 2: Run handlebars\n\nNow, when you run handlebars, if you see a message like this:\n\n```js\nmissing helper {{foo}}\n```\n\nYou can either create the `foo` helper from scratch, or use a helper library that already includes the helpers you need.\n\nAny of the following libraries may be used, but the [liquid-filters][] library might be most useful (during migration, at least).\n\n* [liquid-filters][] - includes a bunch of utility javascript functions that can be registered as handlebars helpers to provide parity with the built-in liquid filters\n* [template-helpers](https://github.com/jonschlinkert/template-helpers) - generic helpers that can be used with any template engine.\n* [handlebars-helpers](https://github.com/helpers/handlebars-helpers) - more than 150 handlebars helpers\n\n**Examples**\n\n```js\nconst handlebars = require('handlebars');\nconst filters = require('liquid-filters');\nconst helpers = require('template-helpers');\n\nhandlebars.registerHelper(filters());\nhandlebars.registerHelper(helpers());\n```\n\n## Conversion Examples\n\nThere are **many more examples** in the [docs folder](./examples.md), as well as [test/fixtures](./test/fixtures) and [test/expected](test/expected).\n\n### Conditionals\n\n**basic operators**\n\nFrom this liquid:\n\n```liquid\n{% if product.type == \"Shirt\" or product.type == \"Shoes\" %}\n  This is a shirt or a pair of shoes.\n{% endif %}\n```\n\nTo this handlebars:\n\n```handlebars\n{{#if (or (is product.type \"Shirt\") (is product.type \"Shoes\"))}}\n  This is a shirt or a pair of shoes.\n{{/if}}\n```\n\n**boolean**\n\nFrom this liquid:\n\n```liquid\n{% if settings.fp_heading %}\n  \u003ch1\u003e{{ settings.fp_heading }}\u003c/h1\u003e\n{% endif %}\n```\n\nTo this handlebars:\n\n```handlebars\n{{#if settings.fp_heading}}\n  \u003ch1\u003e{{ settings.fp_heading }}\u003c/h1\u003e\n{{/if}}\n```\n\n**case**\n\nFrom this liquid:\n\n```liquid\n{% case handle %}\n{% when 'cake' %}\n  This is a cake\n{% when 'cookie' %}\n  This is a cookie\n{% else %}\n  This is not a cookie/cake\n{% endcase %}\n```\n\nTo this handlebars:\n\n```handlebars\n{{#is handle 'cake'}}\n  This is a cake\n{{else is handle 'cookie'}}\n  This is a cookie\n{{ else }}\n  This is not a cookie/cake\n{{/is}}\n```\n\nRequires the [\"is\" helper](https://github.com/nimojs/handlebars-helper-is).\n\n**else**\n\nFrom this liquid:\n\n```liquid\n{% if username and username.size \u003e 10 %}\n  Wow, {{ username }}, you have a long name!\n{% else %}\n  Hello there!\n{% endif %}\n```\n\nTo this handlebars:\n\n```handlebars\n{{#if (and username (gt username.size 10))}}\n  Wow, {{ username }}, you have a long name!\n{{else}}\n  Hello there!\n{{/if}}\n```\n\n**contains**\n\nFrom this liquid:\n\n```liquid\n{% if product.title contains 'Pack' %}\n  This product's title contains the word Pack.\n{% endif %}\n```\n\nTo this handlebars:\n\n```handlebars\n{{#if (contains product.title \"Pack\")}}\n  This product's title contains the word Pack.\n{{/if}}\n```\n\n### Arrays\n\n**Basic loops**\n\nFrom this liquid:\n\n```liquid\n\u003c!-- if site.users = \"Tobi\", \"Laura\", \"Tetsuro\", \"Adam\" --\u003e\n{% for user in site.users %}\n  {{ user }}\n{% endfor %}\n```\n\nTo this handlebars:\n\n```handlebars\n\u003c!-- if site.users = \"Tobi\", \"Laura\", \"Tetsuro\", \"Adam\" --\u003e\n{{#each site.users as |user|}}\n  {{ user }}\n{{/each}}\n```\n\n**Accessing specific items in arrays**\n\nFrom this liquid:\n\n```liquid\n\u003c!-- if site.users = \"Tobi\", \"Laura\", \"Tetsuro\", \"Adam\" --\u003e\n{{ site.users[0] }}\n{{ site.users[1] }}\n{{ site.users[3] }}\n```\n\nTo this handlebars:\n\n```handlebars\n\u003c!-- if site.users = \"Tobi\", \"Laura\", \"Tetsuro\", \"Adam\" --\u003e\n{{get site.users 0}}\n{{get site.users 1}}\n{{get site.users 3}}\n```\n\n### Filters\n\n\u003e Filters are converted to [handlebars subexpressions](http://handlebarsjs.com/expressions.html#subexpressions)\n\nFrom this liquid:\n\n```liquid\n{{ \"Ground control to Major Tom.\" | split: \"\" | reverse | join: \"\" }}\n```\n\nTo this handlebars:\n\n```handlebars\n{{join (reverse (split \"Ground control to Major Tom.\" \"\")) \"\"}}\n```\n\n**Many more examples** in the [docs folder](docs) and [unit tests](test).\n\n## What is this?\n\nThis is a tool for converting projects that use [liquid](https://github.com/Shopify/liquid) templates to use [handlebars](http://www.handlebarsjs.com/) templates.\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble \"Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit\")\n* [handlebars](https://www.npmjs.com/package/handlebars): Handlebars provides the power necessary to let you build semantic templates effectively with no frustration | [homepage](http://www.handlebarsjs.com/ \"Handlebars provides the power necessary to let you build semantic templates effectively with no frustration\")\n\n### Author\n\n**Jon Schlinkert**\n\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 06, 2018._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fliquid-to-handlebars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fliquid-to-handlebars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fliquid-to-handlebars/lists"}