So I looked at the code a bit, and I'm guessing Ram's issue is that Django blocks starting with "if" automatically close with "end", which is great when you don't have "else" blocks, but unfortunate when you do have "else" blocks. Perhaps naively, I don't think it should be too much trouble to just have the "else" blocks pop the last "end" off of output.
Shpaml is intended to be basically semantic-free; i.e. it's totally a syntax layer. So I don't think it's necessarily in the scope of the problem to enforce that else lines actually correctly follow the right if lines. But I agree that if you did want to enforce those semantics, things would get kind of tricky.
It would be really interesting to see a grammar-based approach to this, but from a pragmatic standpoint, I also think it's worth trying the pop-the-last-line-off approach within the current
paradigm.