Skip to content

Instantly share code, notes, and snippets.

@develmaycare
Last active March 18, 2018 18:42
Show Gist options
  • Save develmaycare/64db206549ffb8ec98d139578f07d659 to your computer and use it in GitHub Desktop.
Save develmaycare/64db206549ffb8ec98d139578f07d659 to your computer and use it in GitHub Desktop.
Twitter Bootstrap Row Cycles in Django and Jinja
{# Assuming a page object with one or more instances of a content block: #}
{% for block in page.blocks %}
{# Start a new row every third block. #}
{% cycle '<div class="row">' "" "" %}
<div class="col-md-4">
{{ block }}
</div>
{# End every third row. #}
{% cycle "" "" '</div>' %}
{% endfor %}
{# The row div will need to be closed if the total blocks is not divisible by 3. #}
{% if not page.blocks|length|divisibleby:"3" %}</div>{% endif %}
{# Assuming a page object with one or more instances of a content block: #}
{% for block in page.blocks %}
{# Start a new row every third block. #}
{{ loop.cycle('<div class="row">', "", "") }}
<div class="col-md-4">
{{ block }}
</div>
{# End every third row. #}
{{ loop.cycle("", "", '</div>') }}
{% endfor %}
{# The row div will need to be closed if the total blocks is not divisible by 3. #}
{% if not page.blocks|length %3 == 0 %}</div>{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment