Skip to content

Create a Custom Template

ADL comes with a library of built-in templates, but sometimes you need something specific to your project. This guide walks you through creating a custom Handlebars template from scratch.

A simple template that generates a SQL CREATE TABLE statement for a data object. Along the way, you’ll learn the key Handlebars concepts you need to write your own templates for any output format.

  • An ADL project with at least one data object that has Data Items (columns) defined
  • Familiarity with the basics of How ADL Works
  1. Navigate to the Templates screen.
  2. Create a new template and give it a descriptive name, like “Simple Table DDL”.
  3. The built-in code editor will open, ready for you to write your template.

Start with the static parts — the SQL syntax that will be the same for every table:

CREATE TABLE [{{targetDataObject.name}}] (
);

The {{targetDataObject.name}} expression is a Handlebars placeholder. When ADL processes this template against a data object, it replaces this with the actual object name.

Now add the columns by looping through the Data Items:

CREATE TABLE [{{targetDataObject.name}}] (
{{#each targetDataObject.dataItems}}
[{{name}}] {{dataType}}{{#unless isNullable}} NOT NULL{{/unless}}{{#unless @last}},{{/unless}}
{{/each}}
);

Here’s what each part does:

  • {{#each targetDataObject.dataItems}} — Starts a loop over all columns in the data object.
  • [{{name}}] — Outputs the column name in square brackets.
  • {{dataType}} — Outputs the column’s data type.
  • {{#unless isNullable}} NOT NULL{{/unless}} — Adds NOT NULL if the column doesn’t allow nulls.
  • {{#unless @last}},{{/unless}} — Adds a comma after each column except the last one.
  • {{/each}} — Ends the loop.
  1. Save your template.
  2. Navigate to the Code Preview screen.
  3. Select a data object and your new template.
  4. Check the output — you should see a valid CREATE TABLE statement with all the columns from your data object.

Once the basics work, you can add more features:

{{#if targetDataObject.businessKeyDefinitions}}
CONSTRAINT [PK_{{targetDataObject.name}}] PRIMARY KEY (
{{#each targetDataObject.businessKeyDefinitions}}
[{{businessKeyComponentId}}]{{#unless @last}},{{/unless}}
{{/each}}
)
{{/if}}

ADL provides custom Handlebars helpers for common operations. For example:

  • {{stringReplace name "_" " "}} — Replace underscores with spaces
  • {{now "yyyy-MM-dd"}} — Insert the current date
  • {{lookupExtension targetDataObject.extensions "SchemaName"}} — Look up a custom extension value
{{#if targetDataObject.notes}}
-- {{targetDataObject.notes}}
{{/if}}

Once you’re happy with the template:

  1. Go to the Data Objects screen.
  2. Select a data object and add a template mapping pointing to your new template.
  3. Use the Code Generator to generate the output.
  • Start simple — Get the basic structure working before adding complexity.
  • Preview often — The Code Preview screen is your best friend for testing templates.
  • Study the built-in templates — They’re a great reference for common patterns and Handlebars techniques.
  • Check the Handlebars Helpers — The custom helpers can save you a lot of effort.
  • Keep templates focused — One template, one type of output. It’s easier to maintain several small templates than one giant one.