Skip to content

Instantly share code, notes, and snippets.

@cwebber314
Created May 3, 2013 14:27
Show Gist options
  • Save cwebber314/5509433 to your computer and use it in GitHub Desktop.
Save cwebber314/5509433 to your computer and use it in GitHub Desktop.
from jinja2 import Template
f = open('template.html')
html = f.read()
f.close()
template = Template(html)
signals = {'s1': 0.0,
's2': 1.0,
's3': 'up',
}
html = template.render(signals = signals)
print html
{% macro status(value='') -%}
{% if value == 'up' %}
<a href="up.png"></a>
{% elif value == 'down' %}
<a href="down.png"></a>
{% elif value == 'change' %}
<a href="change.png"></a>
{% elif value > 0.0 %}
<a href="on.png"></a>
{% elif value <= 0.0 %}
<a href="off.png"></a>
{% else %}
{% endif %}
{%- endmacro %}
<html>
<table>
<th><td>Status</td></th>
<tr>{{ status( signals.s1 ) }} <td>
<tr>{{ status( signals.s2 ) }} <td>
<tr>{{ status( signals.s3 ) }} <td>
</td></tr>
</table>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment