Some Markdown Resources:
Markdown in general look here
Markdown Tables look here
Markdown Table Generator look here
I had been trying without success to insert the output of the below code into a table so it is a little better presented.
Here is the code as it was being used on a markdown card:
- type: markdown
title: Last Cleaned
content: |
{% for state in states.input_datetime -%}
{%- if loop.first %}
{% elif loop.last %}
{% else %}
{% endif -%}
{{ state.name | capitalize }} - - - - **{{ state.attributes.day }}/{{ state.attributes.month }}/{{ state.attributes.year }}**
{%- endfor %}
### Daily Action:
Empty Flooded Pipe Settling Tank
Empty Pond Skimmer Basket
As an example…below is what I am looking for in a table:
| System Name | Last Cleaned |
|:-----------:|:------------:|
| xx | xxx |
| xx | xxx |
So I tried modifying my code to include some markdown:
- type: markdown
title: Last Cleaned
content: |
| System Name | Last Cleaned |
|:-----------:|:------------:|
{% for state in states.input_datetime -%}
{%- if loop.first %}
{% elif loop.last %}
{% else %}
{% endif -%}
| {{ state.name | capitalize }} | **{{ state.attributes.day }}/{{ state.attributes.month }}/{{ state.attributes.year }}** |
{%- endfor %}
### Daily Action:
Empty Flooded Pipe Settling Tank
Empty Pond Skimmer Basket
However that did not work as intended. It did seem to work to produce the headings for the table but each row just printed a pipe character beside the output of the loop:
So I played around with the code in the template editor and realised I can get a pretty good representation of a markdown table by stripping out the formatting I had appplied to get some whitespace into my initial markdown card:
CODE:
{% for state in states.input_datetime -%}
{%- if loop.first %}
{% elif loop.last %}
{% else %}
{% endif -%}
| {{ state.name | capitalize }} | {{ state.attributes.day }}/{{ state.attributes.month }}/{{ state.attributes.year }} |
{%- endfor %}
OUTPUT:
| Solids settling | 3/12/2019 |
| Flooded pipe | 2/12/2019 |
| Shadehouse final bio | 27/9/2019 |
| Shadehouse first bio | 24/10/2019 |
| Pump area final bio | 1/1/1970 |
| Pump area first bio | 12/11/2019 |
| Sludge clarifier | 27/9/2019 |
| Sludge screen | 22/11/2019 |
| Pump area swirl | 2/6/2019 |
| Shadehouse swirl | 31/10/2019 |
| Solids settled | 27/11/2019 |
Next step was a bit of a ‘Eureka Moment’ which works not too bad after I added a couple of pipe characters in the middle section of the code as I noticed that the code produced a blank row in the table just under the headings:
- type: markdown
title: Last Cleaned
content: |
| System Name | Last Cleaned |
|:------------|-------------:|
|{% for state in states.input_datetime -%}
{%- if loop.first %}
{% elif loop.last %}
{% else %}
{% endif -%}| |
| {{ state.name | capitalize }} | {{ state.attributes.day }}/{{ state.attributes.month }}/{{ state.attributes.year }} |
{%- endfor %}
### Daily Action:
Empty the Flooded Pipe Settling Tank
Empty the Pond Skimmer Basket
After that I also left-aligned the first column and right-aligned the second column and ended up looking like the below.
Cheers!