change tpl array rules key var to var, if to ifs and loop to loops