yadm-dev / yadm

Yet Another Dotfiles Manager
https://yadm.io/
GNU General Public License v3.0
5.11k stars 175 forks source link

Templates with a matching alternate condition are not used #458

Closed cmvanb closed 1 year ago

cmvanb commented 1 year ago

Describe the bug

A template with an alternate condition that should be matched is not used.

To reproduce

Steps to reproduce the behavior:

  1. yadm init
  2. yadm config local.class example
  3. echo "aaa" > file.txt##template
  4. yadm add file.txt##template
  5. echo "bbb" > file.txt##class.example,template
  6. yadm add file.txt##class.example,template
  7. yadm alt

Expected behavior

I expected the following:

Creating file.txt from template file.txt##class.example,template

Instead this happens:

Creating file.txt from template file.txt##template

Environment

Additional context

I was able to reproduce this with the docker image: script.gz

TheLocehiliosan commented 1 year ago

Files are actually a special kind of alternate. (only one file is ever considered for templates that target a particular path, and it is based on the ordering of the file names, the last one found)

Instead of attempting to combine the example identifiers in the filename, the template should be created like this:

{% if yadm.class == "example" %}
This block is included for class example
{% else %}
This block is included if the class is not example
{% endif %}

Can you merge the content into a single template for the file which has different sections based on class?

cmvanb commented 1 year ago

Thank you for your reply. Yes I did eventually come to that solution.

I would have preferred to use separate files (it feels more cleanly separated), but the class conditional works as needed.

It wasn't clear to me from the documentation that templates and alternates cannot be combined.

Shall I close this issue?

github-actions[bot] commented 1 year ago

This issue has been labeled as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been labeled as stale for 7 days with no activity.