use a context processor and a bit of refactor