Add if user is to YAML (noob programmer) *Solved

I found this template for a welcome message in my mushroom dashboard;

#Welcome template:
{% set time = now().hour %}
{% if (time >= 18) %}
  Good Evening, {{user}}!
{% elif (time >= 12) %}
  Good Afternoon, {{user}}!
{% elif (time >= 5) %}
  Good Morning, {{user}}!
{% else %}
  Hello, {{user}}!
{% endif %}

I want to add if user is ‘mrX’ then write ‘hello little x!’
else just write the username as in the template above implies.
But I am not a programmer and I don’t know YAML so can anyone show me how to do this possibly quite easy trick?
It would mean a lot and help me understand the programming of yaml.
Thanks! :slight_smile:

Do you want to substitute the entire phrase with hello little X?

In other words, you want it to say this:
hello little x!

instead of this:
Good evening, MrX

Good question. Ideally no. I would want the good afternoon etc. to stay and have just the {{user}} be replaced with a nickname if the user is that certain user.

#Welcome template:
{% set time = now().hour %}
{% set user = 'little X' if user == 'MrX' else user %}
{% if (time >= 18) %}
  Good Evening, {{user}}!
{% elif (time >= 12) %}
  Good Afternoon, {{user}}!
{% elif (time >= 5) %}
  Good Morning, {{user}}!
{% else %}
  Hello, {{user}}!
{% endif %}

aha! I thought I had to add a set string at the top… didn’t figure the out I had to use doube ==. Thats explains it. Thanks a bunch! :slight_smile:

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

1 Like