template: move generic logic to base.html