def wptemplate2directory(template_name, wikiprojects, directory=[]):
    """
    Convert a WikiProject template name to a path within the
    WikiProject Directory hierarchy.

    :Parameters:
    template_name : str
      The name of a template (or redirected template) used to tag an article
    wikiprojects : dict
      The wikiprojects directory tree

    :Returns:
    A directory path as a list of strings ordered from top to bottom.
    E.g. "maths rating" returns ["stem", "mathematics"]
    """
    for key in wikiprojects:
        val = wikiprojects[key]
        if 'name' in val and val['name'] == template_name:
            if 'root_url' in val and val['root_url'].endswith('Directory'):
                path_new = directory[:]
                path_new.append(key)
                path = wptemplate2directory(
                    template_name, val['topics'], path_new)
                if path is not None:
                    return path
            return directory
        if 'topics' in val:
            path_new = directory[:]
            path_new.append(key)
            path = wptemplate2directory(template_name, val['topics'], path_new)
            if path is not None:
                return path
    return None