Foreach fix and update template