caption template generation function