build: improve template file parsing