Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created June 12, 2011 23:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/1022139 to your computer and use it in GitHub Desktop.
Save weaverryan/1022139 to your computer and use it in GitHub Desktop.
Why I love Twig - space control, loop index
{# the "{%-" and "-%}" syntax sucks all of the spaces left and right of that tag #}
{# reference: http://www.twig-project.org/doc/templates.html#whitespace-control #}
<a href="{{ upload_path('post_photo', photo.photoPath) }}" class="
{%- if loop.index is divisibleby(3) %}last {% endif -%}
{%- if loop.index > 3 %}not_first_row{% endif -%}
">
<a href="{{ upload_path('post_photo', photo.photoPath) }}" class="last not_first_row">
@marijn
Copy link

marijn commented Jun 13, 2011

This is indeed awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment