Adding template for getAncestors function.