Check if in main loop before outputting template