Articles in this section

Create or explain handlebars using Celigo AI component

Working with handlebars can be challenging, especially when dealing with complex syntax and semantics of the templating language. Any difficulty in interpreting these expressions might lead to errors and issues in the code.

The Celigo AI component allows you to create handlebars expressions using simple English language prompts and explain such expressions in simple language. Describe what you would like the expression to do in plain language, and Celigo AI will generate a suggested template for you that you can refine as required.

When you define your requirement in a plain English prompt, Celigo AI will generate the corresponding handlebars expression for you in the editor. You can even describe handlebars that include multiple fields and complex use cases. Be sure to write your prompt in plain English with clear logic, as you might explain it to a coworker.

Create handlebars expressions from simple language prompts

After the results of your prompt are retrieved, you can enter additional prompts that describe additional changes to the expression that Celigo AI might not have fully understood. All previous prompts are saved and can be viewed or copied until you click Reset conversation or close the editor.

Note

After you reset the conversation, to write new expressions, remove the existing handlebar template.

Click thumbs up or down for each prompt to indicate if the response provided by Celigo AI was helpful or not.

Example 1: A simple expression to capitalize the first letters of the word

Sample JSON

Prompt

AI-generated handlebars template

Output

{ "animal": "canine", "type": "dog, wolf, extant grey wolf" }

Capitalize all in type

{{capitalizeAll type}}

Dog, Wolf, Extant Grey Wolf

Example1_Create.jpg

Example 2: A series of expressions to get an address

Sample JSON

Prompt

AI-generated handlebars template

Preview

{ "first_name": "John", "last_name": "Doe", "gender": "Male", "date_of_birth": "1990-05-15", "email": "johndoe@example.com", "phone_number": "+1 (555) 555-5555", "address": { "street_address": "123 Main Street", "city": "Anytown", "state": "CA", "postal_code": "12345", "country": "United States" } }

Need to concatenate address fields for shipping field

{{address.street_address}}, {{address.city}}, {{address.state}}, {{address.postal_code}}, {{address.country}}

123 Main Street, Anytown, CA, 12345, United States

Can you add your full name as well as ZIP code at last

{{address.street_address}}, {{address.city}}, {{address.state}} {{address.postal_code}}, {{address.country}} - {{first_name}} {{last_name}}

123 Main Street, Anytown, CA 12345, United States - John Doe

Remove country

{{address.street_address}}, {{address.city}}, {{address.state}} {{address.postal_code}} - {{first_name}} {{last_name}}

123 Main Street, Anytown, CA 12345 - John Doe

Example2_Create.jpg

Example 3: A mathematical expression to calculate price and quantity of the products

Sample JSON

Prompt

AI-generated handlebars template

Preview

{ "user": { "id": "123456789", "name": "John Doe", "email": "johndoe@example.com" }, "orders": [ { "order_id": "987654321", "date": "2023-06-28", "items": [ { "product_id": "12345", "name": "Example Product 1", "price": 19.99, "quantity": 2 }, { "product_id": "54321", "name": "Example Product 2", "price": 9.99, "quantity": 1 } ], "total": 49.97, "status": "Delivered" }, { "order_id": "123456789", "date": "2023-06-25", "items": [ { "product_id": "98765", "name": "Example Product 3", "price": 14.99, "quantity": 3 } ], "total": 44.97, "status": "Delivered" } ] }

Multiply price and quantity

{{#each orders}} {{#each items}} Total price for {{name}}: {{multiply price quantity}} {{/each}}

{{/each}}

Total price for Example Product 1: 39.98

Total price for Example Product 2: 9.99

Total price for Example Product 3: 44.97

Example3_Create.jpg

Explain handlebars expression from syntax to simple language

Celigo AI provides an explanation of any part of the handlebars expression that you select in the text. Select the part of the expression that you want Celigo AI to explain, and click Explain selection. Celigo AI will generate an explanation for the selected expression. The selected lines remain highlighted until you close the explanation window. You can reposition the explanation window as needed.

Example 1: Explanation for a simple expression

Sample JSON

Handlebars template

Explain selection

{ "animal": "canine", "type": "dog, wolf, extant grey wolf" }

{{capitalizeAll type}}

The `capitalizeAll` helper is used to capitalize the first letter of each word in the `type` variable.

Example1_Convert.jpg

Example 2: Explanation of a partial selection

Sample JSON

Handlebars template

Explain selection

{ "first_name": "John", "last_name": "Doe", "gender": "Male", "date_of_birth": "1990-05-15", "email": "johndoe@example.com", "phone_number": "+1 (555) 555-5555", "address": { "street_address": "123 Main Street", "city": "Anytown", "state": "CA", "postal_code": "12345", "country": "United States" } }

{{address.street_address}}, {{address.city}}, {{address.state}}, {{address.postal_code}}, {{address.country}}

`{{address.street_address}}` refers to the `street_address` property of the `address` object. It displays the street address of the address.

Example2_Convert.jpg

Example 3: Explanation for a full selection

Sample JSON

Handlebars template

Explain selection

{ "user": { "id": "123456789", "name": "John Doe", "email": "johndoe@example.com" }, "orders": [ { "order_id": "987654321", "date": "2023-06-28", "items": [ { "product_id": "12345", "name": "Example Product 1", "price": 19.99, "quantity": 2 }, { "product_id": "54321", "name": "Example Product 2", "price": 9.99, "quantity": 1 } ], "total": 49.97, "status": "Delivered" }, { "order_id": "123456789", "date": "2023-06-25", "items": [ { "product_id": "98765", "name": "Example Product 3", "price": 14.99, "quantity": 3 } ], "total": 44.97, "status": "Delivered" } ] }

{{#each orders}} {{#each items}} Total price for {{name}}: {{multiply price quantity}} {{/each}} {{/each}}

  1. The `#each orders` block helper is used to iterate over an array or object called `orders`.

  2. Inside the `#each orders` block, another `#each items` block helper is used to iterate over an array or object called `items`, which is a nested property within each `orders` element.

  3. For each `items` element, the template will print the name and calculate the total price by multiplying the `price` and `quantity` properties using the `multiply` helper.

  4. The output will be repeated for each `items` element within each `orders` element.

Example3_Convert.jpg
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.