Conditional templates
Conditional templates are a special subcase of forEach templates. They will filter out data objects based on a condition you provide, and only generate files for the objects that pass the condition.
Template conditions are defined on the first line of the template file, using JavaScript code between @if
and @endif
. You can use multiple lines for the condition, but it must start on the first line.
The condition JavaScript expression must evaluate to an arrow function, that takes a single parameter, called data
, and returns a boolean
value. This parameter will contain the data object that is being processed.
For example:
@if data => data.noGenerateEntityClass !== true @endif
{
"forEach": "entities",
"filename": "Entities/{{pascalCase name}}.cs"
}
---
using System;
namespace Entities
{
/** {{{description}}} */
public class {{pascalCase name}}
{
{{#each fields}}
/** {{{description}}} */
public {{type.cs}} {{pascalCase name}} { get; set; }
{{/each}}
}
}