Skip to content

Instantly share code, notes, and snippets.

@nkrumm
Last active December 24, 2015 00:59
Show Gist options
  • Save nkrumm/6720689 to your computer and use it in GitHub Desktop.
Save nkrumm/6720689 to your computer and use it in GitHub Desktop.
simple_table jinja2 macro
{% 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 %}
@nkrumm
Copy link
Author

nkrumm commented Sep 26, 2013

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

@nkrumm
Copy link
Author

nkrumm commented Sep 26, 2013

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