fixed bug where we were not checking context.template for existence before checking type