def METHOD_NAME(env, template_name, dest, params):
    template = env.get_template(template_name)
    output = template.stream(**params)
    if template_name.endswith(".j2"):
        template_name = template.name[:-3]
    dest = dest / template_name
    dest.parent.mkdir(parents=True, exist_ok=True)
    with dest.open("w") as fh:
        output.dump(fh)
    # Copy file mode over
    source_path = Path(template.filename)
    mode = source_path.stat().st_mode
    dest.chmod(mode)
    return dest