Add resursive tree_gen method to template