at a high level, could you just pass this info to the template and then remove the "same code in two places" problem?