ref, id and nested template support