implement context reference lookups for templates