rewrote utGallery::writeTemplate to avoid unnecessary copies