Move pre-build before generating template, so that variables are available