Last active
March 18, 2018 18:42
-
-
Save develmaycare/64db206549ffb8ec98d139578f07d659 to your computer and use it in GitHub Desktop.
Twitter Bootstrap Row Cycles in Django and Jinja
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
{# 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 %} |
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
{# 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