> ## Documentation Index
> Fetch the complete documentation index at: https://docs.freeplay.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Advanced Templating (Mustache)

> Use Mustache syntax to add conditionals, loops, and dynamic content to your prompt templates.

## Overview

<img src="https://mintcdn.com/freeplay-485a287e/X8uH3NfMBEz8W97Z/images/2dad481328e882776c8219dcc0fa88ab00fdfbcd3717a8ea42abaf7855cfb57f-image.png?fit=max&auto=format&n=X8uH3NfMBEz8W97Z&q=85&s=505209e9e514f4a6a127935f94c437c7" alt="" width="3248" height="2112" data-path="images/2dad481328e882776c8219dcc0fa88ab00fdfbcd3717a8ea42abaf7855cfb57f-image.png" />

In addition to the basic prompt template features in Freeplay, we also support advanced prompt templating based on Mustache ([full docs here](https://mustache.github.io/mustache.5.html)). Mustache is a logic-less template syntax used to dynamically render new data within your prompts. It can be used for more advanced prompt templating use cases, like using conditional statements, if/else logic, and passing lists of variables into a prompt.

Some benefits include:

* **Dynamic Content Generation:** Create more flexible and context-aware prompts.
* **Simplified Template Management:** Less need for multiple similar templates, as one template can handle various data scenarios.

In practice, Mustache gives advanced controls to create more complex prompt templates, and is still user-friendly enough for non-developers to interpret and edit in Freeplay. However, just like the variable names described above, using advanced Mustache features depends on a strong contract with the code that will be used by your system to interact with the prompt template. It's important to align on expectations about what's in the code for anyone editing prompts in Freeplay.

Basic Mustache Syntax

[Mustache](https://mustache.github.io/mustache.5.html) templates are simple yet powerful. They work by expanding tags in a template using values provided in a hash or object. A Mustache template might look like this:

```
{{#repo}} // IF
  {{name}}
{{/repo}}
{{^repo}} // ELSE
  No repos :(
{{/repo}}
```

Given a hash with data for `repo` and `name` Mustache will render this template with appropriate substitutions.

**Supported Tag Types**

* **Variables:** Basic tags like \{\{name}} are replaced with the value associated with that key.
* **Dotted Names:** For nested objects, use dotted names like \{\{client.name}}.
* **Sections:** For conditional rendering, use sections like \{\{#logged\_in}}...\{\{/logged\_in}}. This will render the block only if logged\_in is true or non-empty.
* **Inverted Sections:** Use \{\{^logged\_in}}...\{\{/logged\_in}} for the opposite: rendering when logged\_in is false or empty.

Note that we do not follow the Mustache spec exactly. We don't currently support all tag types (see limitations below). Also, our Mustache implementation does /not/ escape special characters (quotes, braces, etc.). We think this is more intuitive, but is not technically aligned to the Mustache spec.

**Limitations**

We currently disallow Mustache Partials (syntax like `{{> prompt_rules}}`) that would recursively include other prompts or code.

***

What's Next

Dig deeper into Prompt Management and learn about Prompt Bundling, or jump into Evaluations.

* [Prompt Bundling](/core-concepts/prompt-management/prompt-bundling)
* [Evaluations](/core-concepts/evaluations/evaluations)
