Last active
December 24, 2015 00:59
-
-
Save nkrumm/6720689 to your computer and use it in GitHub Desktop.
simple_table jinja2 macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro simple_table(data, rowlink_prefix, column_order, column_names, id_field="_id") %} | |
<table class="table table-hover table-condensed" data-provides="rowlink"> | |
{{ table_header(column_names|default(column_order|default(data[0])))}} | |
<tbody> | |
{% for row in data %} | |
<tr> | |
{% for item in column_order|default(row) %} | |
{% if (rowlink_prefix != None) and (item == id_field) %} | |
<td><a href='{{ rowlink_prefix + row[item] | string }}'>{{ row[item] }}</a></td> | |
{% else %} | |
<td>{{ row[item] | safe }}</td> | |
{% endif %} | |
{% endfor %} | |
</tr> | |
{% endfor %} | |
</tbody> | |
</table> | |
{% endmacro %} | |
{% macro table_header(columns) %} | |
<thead><tr> | |
{% for name in columns %} | |
<th>{{ name }}</th> | |
{% endfor %} | |
</tr></thead> | |
{% endmacro %} | |
for bootstrap with bootstrap-rowlink. Uses "_id" field and rowlink_prefix to create an href for each row. optional column_order and column_names can re(order|name) your table
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for bootstrap with bootstrap-rowlink. Uses "_id" field and rowlink_prefix to create an href for each row. optional column_order and column_names can re(order|name) your table