I feel this is a bit too much logic to have in the template. Can you put it in the generator intead?