Another IfModulo Template Tag Or If Else End Tutorial
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.
More from Aware Labs
- Retiring Old Posts To Keep Django Fresh
- Constructive reasons to use Django instead of Rails (Proxied)
- Django Deserializer Bug On Foreign Key When None
- WordPress Adventure – NoScript Hack Solved
- Django Generic Relations Made Easier
Aware Labs Recommends
- WordPress For Business (The Arkayne Blog)
- Popularizing Django — Or Reusable apps considered harmful. (USwaretech)
- An Interview with Jacob Kaplan-Moss – Creator of Django (USwaretech)
-
ruddy
-
pkenjora

![Recommend [AwareLabs]](http://s3.amazonaws.com/arkayne-media/img/badge/logo-recommend-badge-medium.png)