Use Handlebars to add conditions to your templates
Dynamic Content:
Conditional Content:
Prompt Variations:
Log into Langtail and select your project.
Navigate to 'Prompts' to either open an existing prompt or create a new one.
In the 'Template' section, craft your prompt.
{{variableName}}
$date
helper to print the current date in the format MMMM dd, yyyy
:
dateVar
variable is set to 2024-09-01
, this example will print just “09”:
{{#if condition}}...{{/if}}
hour
is a variable that you would set based on the user’s
local time before sending the prompt to the LLM.
eq
, ne
, lt
, gt
, lte
, gte
, and
, or
can be used to evaluate conditions. This enables you to create dynamic prompts that respond to specific input data.
{{#if (helperName arg1 arg2)}}...{{/if}}
{{#if ...}}
block to evaluate conditions.if
, else
, each
, unless
, and with
. Here’s how it works:
{{#if}}
, {{#each}}
, {{#unless}}
, {{#with}}
) is automatically removed. This prevents unintended breaks that could confuse the LLM.{{else}}
: Newlines immediately before and after {{else}}
are removed. This ensures that the content before and after the {{else}}
is treated as a continuous block without unnecessary breaks.{{/if}}
, {{/each}}
, {{/unless}}
, {{/with}}
) are also removed. This action keeps the template compact and avoids introducing breaks that the LLM might misinterpret.{{#if}}
tag as follows: