Skip to main content

render-templates

This section provides the reference for the render-templates Declarative Hook.


A Declarative Hook of type render-templates allows you to conditionally generate files. By associating this Hook with a condition, you control whether specific files will be generated. See the usage example below:

name: Declarative Hooks Plugin example
description: My Plugin with Declarative Hooks
types:
- app
spec:
inputs:
- label: first input
type: text
name: first_input
hooks:
- type: render-templates
trigger: after-render
path: templates-java
condition:
variable: language
operator: "=="
value: java
- type: render-templates
trigger: after-render
path: templates-kotlin
condition:
variable: language
operator: "=="
value: kotlin

In the example above, when the language input is set to java, the files from the templates-java folder are generated. If the value is kotlin, the files from the templates-kotlin folder are generated.

Available Actions

trigger:

Field used to define when file generation should occur.

  • before-input:
    Executes the Declarative Hook before receiving the user input parameters.

    trigger: before-input
  • before-render:
    Executes the Declarative Hook before the Plugin generates or updates files in the project.

    trigger: before-render
  • after-render:
    Executes the Declarative Hook after the Plugin generates or updates files in the project.

    trigger: after-render

condition:

caution

The directory defined in the condition must be outside the templates folder.

Field that defines a condition for running the Declarative Hook.

variable:
Variable used in the condition, defined by the Plugin’s inputs or computed-inputs. See more details about inputs in YAML files in this section: inputs in YAML files.

operator:
Conditional operator used in the comparison between variable and value.

The following table lists the available operators and their descriptions:

OperatorDescription
"=="Validates if the values are equal.
"!="Validates if the values are different.
">"Validates if the variable is greater than the value.
"<"Validates if the variable is less than the value.
">="Validates if the variable is greater than or equal to the value.
"<="Validates if the variable is less than or equal to the value.
containsAnyValidates if the list-type variable contains any of the values in value. If value is not a list, it is treated as a single-element list. If value is an empty list, it returns false.
containsAllValidates if the list-type variable contains all the values in value. If value is not a list, it is treated as a single-element list. If value is an empty list, it returns true.
containsOnlyValidates if the list-type variable is a permutation of the items in value. If value is not a list, it is treated as a single-element list.

value:
Reference value used by the operator to evaluate the condition.

warning

Use double quotes for the following operators: "==", "!=", ">", ">=", "<", "<=".

Examples

The following examples use a list input named field_4 to demonstrate conditional operators.

  • containsAny
# Operator containsAny
- label: Should appear if field 4 contains any value item1
type: text
name: contains_any_operator_test_1
default: ok
condition:
variable: field_4
operator: containsAny
value: item1
- label: Should appear if field 4 contains any value item1, item2
type: text
name: contains_any_operator_test_2
default: ok
condition:
variable: field_4
operator: containsAny
value: [item1, item2]
  • containsAll
# Operator containsAll
- label: Should appear if field 4 contains all values item1, item2
type: text
name: contains_all_operator_test_1
default: ok
condition:
variable: field_4
operator: containsAll
value: [item1, item2]