fix template foreach scoping