It strikes me that this is something that should be handled by a fallback in the template directories, not in the template/context itself. This is the way that the admin allows you to override admin base templates with local themes/customizations.