change thor_template into a generator