Skip to content

Another IfModulo Template Tag Or If Else End Tutorial

by Paul Kenjora on March 2nd, 2008

It seems that everyone on the world is rolling their own ifmodulo template tag these days. I figured I’d jump on the bandwagon. The problem I was attempting to solve was one of for loop counting for the purpose of creating multi column tables. For one of my pet projects Joost List, I wanted to create a 2 column layout for the videos. I looked at existing solutions and the first one that popped up was the Django Snippets: If Modulo Tag solution. I looked at the solution, thought it was overkill for what I needed, and proceeded to roll my own tag. The code is below but before copying it read the Django DIVISIBLEBY documentation.

I should have read the comments, Django already has a built in solution for if modulo called DIVISIBLEBY.

I’ll say it again, Django already has a built in solution for if modulo called DIVISIBLEBY.

I almost didn’t post this but I figured stating the above clearly will save someone some time. For the rest of you please feel free to use the template tag code above as a fairly good starting point for writting if-else-end type tags.

  • :-) it happens, but fun :-D
  • Woohoo, the Arkayne widget picked up some awesome blogs on this post. My anti-evil plan to replace Google is working. Sigh, I can dream big, but who knows for now I'm very happy with the way the linking algorithm is performing.

    Feed more Django blogs into Arkayne!
blog comments powered by Disqus