precise mod handling for vals/vars in templates