lib/template: move template related code to its own subdir