adding function expanding to templates