ast: fixed handling of templates