yadm-dev / yadm

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

How can I use multiple classes in default template? #485

Closed piny940 closed 6 months ago

piny940 commented 6 months ago

This question is about

Describe your question

I've added multiple classes using yadm config local.class Hoge1 and yadm config --add local.class Hoge2.

$ yadm config --get-all local.class
Hoge1
Hoge2

Now, how can I utilize these classes in a template file?

I want to achieve something like this in config##template:

{% if "Hoge1" in yadm.classes %}
Hoge1
{% endif %}

I'm certain this question is related to #304 , but I'm unable to figure out how to use multiple classes in template files.

Thank you.

[A clear and concise description of the question.]

rasa commented 6 months ago

In https://yadm.io/docs/templates it says

If multiple classes are defined, yadm.class=="someclass" will be true if any of the defined classes are “someclass”.

Please try that, and let us know your results.

piny940 commented 6 months ago

The classes are mango and peach:

$ yadm config --get-all local.class
mango
peach

In the test##template, I've written:

{% if yadm.class=="mango" %}
mango
{% endif %}
{% if yadm.class=="peach" %}
peach
{% endif %}

However, the content of 'test' only became:

peach

It appears it only checks the result of yadm config local.class.

rasa commented 6 months ago

@piny940 Can you try

{% if yadm.classes=="mango" %}
mango
{% endif %}
{% if yadm.classes=="peach" %}
peach
{% endif %}

Perhaps the doc is wrong on the syntax.

piny940 commented 6 months ago

Unfortunatlly, it didn't work. The content of test became empty.

piny940 commented 6 months ago

I've written test##template as follows:

{% if yadm.classes=="mango" %}
mango
{% endif %}
{% if yadm.classes=="peach" %}
peach
{% endif %}

Variables:
{{ yadm.class }}
{{ yadm.classes }}

Then the content of test became:


Variables:
peach
{{ yadm.classes }}

It appears yadm.classes does not work in template file.

piny940 commented 6 months ago

I checked the version of yadm and I found it was old.

$ yadm version
yadm 3.1.1

When I upgrade yadm to the latest version, everything worked fine. Thank you for your support.