Handle loops within {%block%} and {%extend%}

When base and parent templates within {%block%} tags contain for loops,
there is an 'unsafe L' error due to leaky case expressions.  This wraps the
case statement in an anonymous function call, containing the 'L' variable,
and preventing a crash.

This also adds the relevant test.