Rule based templating