render-templates
In this section, you will find reference of a Declarative Hook of the type render-templates.
A Declarative Hook of the type render-templates
can be used to perform conditional file generation. By using a Declarative Hook of this type, connected to a condition, you can control whether or not some file will be generated according to a condition. Check a usage example:
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 above case, when the input language
was filled in with the value java
, it generated the files that are in the folder templates-java
. If the input is filled in with the value kotlin
, it generates the files that are in the templates-kotlin
folder.
Available Actions
trigger
:
Field to define triggers that inform the moment in which the generation of files should occur.
before-input
:
Executes the Declarative Hook before receiving the input parameters from the user person.
trigger: before-input
before-render
:
Runs the Declarative Hook before the Plugin generates or updates files in the project.
trigger: before-render
after-render
:
Runs the Declarative Hook after the Plugin generates or updates files in the project.
trigger: after-render
condition:
The condition directory needs to be outside the 'templates' folder.
A field that determines a condition to execute the Declarative Hook.
variable
:
Variable used in the condition. The variable is defined by the inputs
and computed-inputs
of a Plugin. Check out more details in the inputs in yaml files section.
operator
:
A conditional operator is used in the operation between variable
and value
. The operators are:
Operator | Description |
---|---|
"==" | Validates if the values are equal . |
"!=" | Validates if the values are different . |
">" | Validates if a variable is greater than 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 . |
containsAny | Validates if the list-type variable contains any values in ** value**. If ** value** is not a list, it treats ** value** as a list with a single element. If ** value** is an empty list, it returns **false**. |
containsAll | Validates if the list-type variable contains all the values in ** value**. If ** value** is not a list, it treats ** value** as a list with a single element. If ** value** is an empty list, it returns **true**. |
containsOnly | Validates if the list-type variable is a permutation of the items in ** value**. If ** value** is not a list, it treats ** value** as a list with a single element. |
value
:
Reference value for the operator to check the conditional.
You must use double quotes for the following operators: "=="
, "!="
, ">"
, ">="
, "<"
, "<="
.
Examples
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]