Skip to content

Allow more if statements in templates #38

@anikaweinmann

Description

@anikaweinmann

With #36 you can use in a template a if statement to check if a variable is defined or not, e.g.

{
	"id": "if_statement",
	"description": "Placeholder json file with if statement",
	"template": {
		"version": "1",
		"list": [
			{
				"module": "r.mapcalc",
				"id": "r.mapcalc_test",
				"inputs": [
					{% if region_union is defined %}
					{
						"param": "region",
						"value": "{{ region_union }}"
					},
					{% endif %}
					{
						"param": "expression",
						"comment": "output = r.mapcalc result, string; value = raster value (default=0.428), float",
						"value": "{{ output }} = {{ value|default(0.428) }}"
					}
			  ]
			}
		]
	}
}

If the variable region_union is only used for the checking and not used as value for the region, the variable would not be listed by requesting the actinia-module. This should be changed.

Also other if statements should be supported e.g.:

{
	"id": "different_if_statements",
	"description": "Placeholder json file with different if statements as example",
	"template": {
		"version": "1",
		"list": [
			{%- if "test1" in test_list or "test2" in test_list -%}
			{
				"module": "r.mapcalc",
				"comment": "if to check if a sting is in a list",
				"id": "r.mapcalc_test",
				"inputs": [
					{
						"param": "expression",
						"value": "test_list_result = 5"
					}
			  ]
			},
			{%- endif -%}
			{%- if "var" == "test" -%}
			{
				"module": "r.mapcalc",
				"comment": "if to check var is 'test'",
				"id": "r.mapcalc_test",
				"inputs": [
					{
						"param": "expression",
						"value": "test_var_result = 5"
					}
			  ]
			},
			{%- endif -%}
			{%- if "var2" == "True" -%}
			{
				"module": "r.mapcalc",
				"comment": "if to check if var2 is True",
				"id": "r.mapcalc_test",
				"inputs": [
					{
						"param": "expression",
						"value": "test_var2_result = 5"
					}
			  ]
			},
			{%- endif -%}
			{
				"module": "r.mapcalc",
				"id": "r.mapcalc_test",
				"inputs": [
					{% if region_union is defined %}
					{
						"param": "region",
						"comment": "if to check if a variable is set",
						"value": "union"
					},
					{% endif %}
					{
						"param": "expression",
						"comment": "output = r.mapcalc result, string; value = raster value (default=0.428), float",
						"value": "{{ output }} = {{ value|default(0.428) }}"
					}
			  ]
			}
		]
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions