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

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

Closed
1 of 8 tasks
piny940 opened this issue May 3, 2024 · 6 comments
Closed
1 of 8 tasks

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

piny940 opened this issue May 3, 2024 · 6 comments
Labels

Comments

@piny940
Copy link

piny940 commented May 3, 2024

This question is about

  • Installation
  • Initializing / Cloning
  • Alternate files
  • Jinja templates
  • Encryption
  • Bootstrap
  • Hooks
  • Other

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
Copy link
Contributor

rasa commented May 3, 2024

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
Copy link
Author

piny940 commented May 3, 2024

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
Copy link
Contributor

rasa commented May 3, 2024

@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
Copy link
Author

piny940 commented May 3, 2024

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

@piny940
Copy link
Author

piny940 commented May 3, 2024

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
Copy link
Author

piny940 commented May 3, 2024

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.

@piny940 piny940 closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants