--- title: "Tools.Mustache" slug: "toolsmustache" tags: ["luminesce ", "provider"] updated: 2026-02-06T13:47:00Z published: 2026-02-06T13:47:00Z canonical: "support.lusid.com/toolsmustache" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.lusid.com/llms.txt > Use this file to discover all available pages before exploring further. # Tools.Mustache | **Type** | **Read/write** | **Author** | **Availability** | | --- | --- | --- | --- | | [Direct provider](/v1/docs/what-are-a-data-provider-and-a-direct-provider) | Read | Finbourne | Provided with LUSID | The `Tools.Mustache` provider enables you to write a [Luminesce query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that applies [Mustache](https://mustache.github.io/mustache.5.html) templating to a dataset. You can use this provider in conjunction with other providers to return data in Mustache templating, [see example 4](/v1/docs/toolsmustache#example-4-creating-a-mustache-template-which-outputs-multiple-rows). ## Basic usage ```sql @data = select from where ; @mustache_txt = use Tools.Mustache with @data {{#@data}}  {{}} {{/@data}} enduse; select * from @mustache_txt ``` ## Input tables `Tools.Mustache` can take in different kinds of variables and outputs a table of data which can take various forms: | **Input** | **Output** | **Information** | **Syntax** | | --- | --- | --- | --- | | `@@variables` | Table of data with one row and column | Simple scalar variables which can be used within Mustache templates. [See example 1.](/v1/docs/toolsmustache#example-1-applying-mustache-templating-to-some-data) | ```sql @@data = select ; @mustache_txt = use Tools.Mustache with @@data {{@@data}} enduse; select * from @mustache_txt ``` | | `@variables` | Table of data with one row and column | Full tables of data which can be used within Mustache templates. Requires a specific syntax to be able to iterate over rows. Using this syntax, column names can be specified within Mustache templates to return values. [See example 2.](/v1/docs/toolsmustache#example-2-creating-a-mustache-template-with-a-table-of-data) | ```sql @data = select from ; @mustache_txt = use Tools.Mustache with @data {{#@data}} {{}} {{/@data}} enduse; select * from @mustache_txt ``` | | `@partials` | Table of data with one row and column | A table with two columns (`Name` and `Template`) of type string which allow partial templates to be defined for reuse, for example when creating [custom views](/v1/docs/using-sysadminsetupview-to-create-custom-views). Requires a specific syntax. [See example 3.](/v1/docs/toolsmustache#example-3-creating-a-reusable-partial-mustache-template) | ```sql @data = select as , as ; @partials = select '' as Name, '' as Template where 1 = 2 --required, this just has the effect of creating two columns union all values ('', '{{} {{}}') ; @mustache_txt = use Tools.Mustache with @partials, @data {{#@data}} {{>}} {{/@data}} enduse; select * from @mustache_txt ``` | | `@foreach` | Table of data with one or more rows and columns | Returns all columns specified in a multi-line result, plus an additional column containing the populated Mustache template for each row. [See example 4.](/v1/docs/toolsmustache#example-4-creating-a-mustache-template-which-outputs-multiple-rows) Also returns a nested table if `AsTable` is specified in the Mustache template. [See example 5.](/v1/docs/toolsmustache#example-5-creating-a-mustache-template-which-outputs-a-nested-table) | ```sql @foreach = select [..., ] from ; @mustache_txt = use Tools.Mustache with @@foreach {{}} {{}} enduse; select * from @mustache_txt ``` | ## Examples ### Example 1: Applying Mustache templating to some data In this example, we use a simple scalar variable with `Tools.Mustache` to return a table of data with one column and one row which contains our completed Mustache template. ```sql @@txt = select 'just like this'; @mustache_txt = use Tools.Mustache with @@txt You can use Mustache templating {{@@txt}} enduse; select * from @mustache_txt ``` The table of data returned looks like this: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/e3c3b4e5-a7e0-4deb-bdc3-6ddf7590af89.png?sv=2026-02-06&spr=https&st=2026-11-04T02%3A13%3A53Z&se=2026-11-04T03%3A13%3A53Z&sr=c&sp=r&sig=%2F5LVBGfykxDDWIucCDtZiBLqYN2O%2Fd0%2FTVwb44Eo0t0%3D) ### Example 2: Creating a Mustache template with a table of data In this example, we create an input table of data which we use with `Tools.Mustache` to create a Mustache template. ```sql @data = select 'this' as SomeText, 'that' as MoreText, 10 as SomeNumber;     @mustache_txt = use Tools.Mustache with @data {{#@data}}  You can use {{SomeText}} and {{MoreText}} in Mustache templating.  And even {{SomeNumber}}! {{/@data}} enduse; select * from @mustache_txt ``` The table of data returned by the query looks like this, with the Mustache template populated with values: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/3aeaa319-a83d-4ff8-9576-07fbb4615ba0.png?sv=2026-02-06&spr=https&st=2026-11-04T02%3A13%3A53Z&se=2026-11-04T03%3A13%3A53Z&sr=c&sp=r&sig=%2F5LVBGfykxDDWIucCDtZiBLqYN2O%2Fd0%2FTVwb44Eo0t0%3D) ### Example 3: Creating a reusable partial Mustache template You can use a special kind of variable called `@partials` in your query to define a reusable partial Mustache template which you could use, for example, to create [custom views](/v1/docs/using-sysadminsetupview-to-create-custom-views) that output a populated Mustache template. In this example, we create a table of data and populate a `@partials` variable with the required special syntax. We then use both variables with the `Tools.Mustache` provider to return a single cell table of data. ```sql @some_data = select 'x' as SomeText, 'y' as MoreText, 4 as SomeNumber;   @partials = select '' as Name, '' as Template where 1 = 2 -- required, this just has the effect of creating two columns union all values    ('XRow', '{{SomeText}} : {{SomeNumber}} on {{MoreText}}'),    ('YRow', '{{MoreTxt}}') ; @mustache_txt = use Tools.Mustache with @partials, @some_data {{#@some_data}} {{>XRow}} {{/@some_data}} and {{#@some_data}} {{>YRow}} {{/@some_data}} enduse;     select * from @mustache_txt ``` The table of data returned by the query looks like this, with the partial template populated with data from our `@some_data` variable, all within the larger Mustache template: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/28ff55af-3dd5-41d3-b656-57cd789d5cb2.png?sv=2026-02-06&spr=https&st=2026-11-04T02%3A13%3A53Z&se=2026-11-04T03%3A13%3A53Z&sr=c&sp=r&sig=%2F5LVBGfykxDDWIucCDtZiBLqYN2O%2Fd0%2FTVwb44Eo0t0%3D) ### Example 4: Creating a Mustache template which outputs multiple rows In this example, we use a special kind of variable called `@foreach` with the `Tools.Mustache` provider to return all columns and rows in the table, plus an additional column containing a populated Mustache template for each row. ```sql @foreach = select distinct TableName, FieldName, DataType from Sys.Field;     @mustache_txt = use Tools.Mustache with @foreach {{TableName}}.{{FieldName}} -> {{DataType}} enduse; select * from @mustache_txt ``` The first ten rows of the table of data returned by the query looks like this: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/1a38f127-e021-4476-9f8d-5f59f197016f.png?sv=2026-02-06&spr=https&st=2026-11-04T02%3A13%3A53Z&se=2026-11-04T03%3A13%3A53Z&sr=c&sp=r&sig=%2F5LVBGfykxDDWIucCDtZiBLqYN2O%2Fd0%2FTVwb44Eo0t0%3D) ### Example 5: Creating a Mustache template which outputs a nested table In this example, we first define a `@foreach` variable which uses the `group_concat` aggregate function with a data field. This variable is then used with `Tools.Mustache` to create a Mustache template that outputs a nested table in an additional column. Note the specific syntax used in `@mustache_txt`. When constructing the Mustache message, `AsTable` is appended to the column we want to format as a nested table. Within the column which is to become a nested table, fields are split on `,` and each field is referred to by its order number e.g., `{{1}}`, `{{2}}`. ```sql @foreach = select TableName, group_concat(FieldName) filter (where FieldType = 'Column') as Columns from Sys.Field group by TableName;     @mustache_txt = use Tools.Mustache with @foreach {{TableName}}: {{#ColumnsAsTable}}  {{1}} {{/ColumnsAsTable}} enduse; select * from @mustache_txt ``` The first ten rows of the table of data returned by the query looks like this: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/6f5865dd-1912-4b6e-af45-468a44547613.png?sv=2026-02-06&spr=https&st=2026-11-04T02%3A13%3A53Z&se=2026-11-04T03%3A13%3A53Z&sr=c&sp=r&sig=%2F5LVBGfykxDDWIucCDtZiBLqYN2O%2Fd0%2FTVwb44Eo0t0%3D)