Make Template more readable

I am trying to modify a template to produce a ‘cleaner’ result and I’m wondering how I amend the template to:
a) remove the quotation marks
b) have the current_position value to appear next to the friendly_name on the same line for each?

The current result:
Screenshot 2024-08-13 at 14.49.06

Template:

{% set updates =  expand('cover.all_blinds') | selectattr('state', 'eq', 'open') | list %}
{% set ns = namespace(result=[] ) %}
{% for item in updates %}
  {% set ns.result = ns.result + [[item.attributes.friendly_name], [item.attributes.current_position] ] %}
{% endfor %}
{{ ns.result | join('\n') | replace (' Blinds', '') | replace (' (Simple)', '') | replace ('[', '')| replace (']', '') | replace ('.0', '%') }}

Any reason why you first add them all to the namespace before outputting it?
Can’t you output it directly?

A wild guess:

{% set updates =  expand('cover.all_blinds') | selectattr('state', 'eq', 'open') | list %}
{% for item in updates %}
  {{ item.attributes.friendly_name | replace (' Blinds', '') | replace (' (Simple)', '') }} - {{ item.attributes.current_position | int }}% 
{% endfor %}
1 Like
{% set ns = namespace(result=[] ) %}
{% for item in expand('cover.all_blinds') | selectattr('state', 'eq', 'open') %}
  {% set name = item.attributes.friendly_name | replace (' Blinds', '') | replace (' (Simple)', '') %}
  {% set position = item.attributes.current_position | int %}
  {% set ns.result = ns.result + [ name ~ ' ' ~ position ~ '%' ] %}
{% endfor %}
{{ ns.result | join('\n') }}
1 Like

@Hellis81 I just used a template found in another post where the OP needed a similar template for the same reason as myself and it included the namespace. I just edited that template to suit my needs up to where I could.

@petro That works as expected.

Thanks for your help.