Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested ifs for built-in template processor #436

Open
nolith opened this issue Sep 9, 2022 · 1 comment
Open

Support nested ifs for built-in template processor #436

nolith opened this issue Sep 9, 2022 · 1 comment

Comments

@nolith
Copy link

nolith commented Sep 9, 2022

Describe the bug

A template with a nested if do not work and renders with an extra {% endif %}

To reproduce

Can this be reproduced with the yadm/testbed docker image: No - I wasn't able to make yadm alt work on the container

Steps to reproduce the behavior:

  1. Run command
cat << EOF > test.conf\#\#template
{% if yadm.os == "Darwin" %}
{% if yadm.arch == "arm64" %}
macOS arm64
{% else %}
macOS amd64
{% endif %}
{% endif %}
EOF
  1. Run command yadm add test.conf##template
  2. Run command yadm alt
  3. See error cat test.conf
macOS arm64
{% endif %}

Expected behavior

test.conf should have only included one line macOS arm64

Environment

  • Operating system: macOS
  • Version yadm: 3.2.1
  • Version Git: 2.37.2

Additional context

[Add any other context about the problem here.]

@nolith nolith added the bug label Sep 9, 2022
@TheLocehiliosan
Copy link
Member

This is currently working as intended. The built-in template processing is for very simple cases, and does not support nested conditionals. I'll change this issue to be a feature request.

@TheLocehiliosan TheLocehiliosan changed the title templates with nested if are not working Support nested ifs for built-in template processor Sep 13, 2022
erijo added a commit to erijo/yadm that referenced this issue Oct 27, 2024
The awk script now performs all processing in the BEGIN block using an
implementation that is capable of handling nested if statements. This fixes
issue yadm-dev#436. Includes are now handled in the same way as the main file which
means that recursive includes and if statements in includes works as
expected. This fixes yadm-dev#406.

All variables are handled in the same way now so it's now possible to use env
variables in if statements. This fixes yadm-dev#488.

Also add support for != in addition to == (fixes yadm-dev#358). Thus it's now
e.g. possible to check if a variable is set (yadm-dev#477) by doing:

{% if yadm.class != ""%}
Class is set to {{ yadm.class }}
{% endif %}

Possible breaking change: An error will be issued if a non-existent yadm or env
variable is referenced in an if statement or in a variable substitution.
erijo added a commit to erijo/yadm that referenced this issue Oct 27, 2024
The awk script now performs all processing in the BEGIN block using an
implementation that is capable of handling if statements which contain nested
if statments (fixes yadm-dev#436). To make nested ifs look better, if, else and endif
lines can now have optional whitespace before {%.

Includes are now handled in the same way as the main file which means that
included files can both include other files and have if statements in addition
to variables (fixes yadm-dev#406). Include lines can now also have optional whitespace
before {%.

All variables are handled in the same way now so it's now possible to use env
variables in if statements (fixes yadm-dev#488).

Also add support for != in addition to == (fixes yadm-dev#358). Thus it's now
e.g. possible to check if a variable is set (yadm-dev#477) by doing:

{% if yadm.class != ""%}
Class is set to {{ yadm.class }}
{% endif %}

Possible breaking change: An error will be issued if a non-existent yadm or env
variable is referenced in an if statement or in a variable substitution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants