Improve templates

Work on https://github.com/pi-engine/pi/issues/1285 and https://github.com/pi-engine/pi/issues/1277