Conditional output

I have some input text that I always need, but in the output I like to show it depending on an input condition (boolean: Show text Y/N).

I can solve this by repeating the code: once with the {% ic %}-tag, once without it, in combination with the if-statement.

However, this means that all code needs to be doubled, something I rather like to avoid.

So I tried a workaround, see below.

{% input period.custom.berekeningniettonen.rc as:boolean %} Tekst niet mee opnemen in output?

{% assign niet_tonen = period.custom.berekeningniettonen.rc %}

{% if niet_tonen == true %}

{% capture tonen_ic %}
{% raw %}
{% ic %}
{% endraw %}
{% endcapture tonen_ic %}

{% else %}

{% capture tonen_ic %} {% endcapture tonen_ic %}

{% endif %}

{{ tonen_ic }}

However, it seems the {% raw %} also works on the {% ic %} when I use {{ tonen_ic }}, the {% ic %} code is not executed when I do like this…

Would there be another way to solve this?

Thanks.

Ward

Hello @Warde,

Couldn’t you get the needed result by using an ifi-statement on your boolean?

Like


{% ifi niet_tonen %}
This text will always be shown in input, and only in output when the boolean is checked
{% endifi %} 

The ifi-statement means: when the if-statement is fullfiled, then it’ll be displayed in output.

Care to try?

Right, forgot about this one, never used it before, thanks Sven!