Adding loops into templates