refactor(template): extract duplicate code for header and footer