def create_qgis_template_output(output_path, layout):
    """Produce QGIS Template output.

    :param output_path: The output path.
    :type output_path: str

    :param composition: QGIS Composition object to get template.
        values
    :type composition: qgis.core.QgsLayout

    :return: Generated output path.
    :rtype: str
    """
    # make sure directory is created
    dirname = os.path.dirname(output_path)
    if not os.path.exists(dirname):
        os.makedirs(dirname)

    context = QgsReadWriteContext()
    context.setPathResolver(QgsProject.instance().pathResolver())

    layout.saveAsTemplate(output_path, context)
    return output_path
Produce QGIS Template output.

    :param output_path: The output path.
    :type output_path: str

    :param composition: QGIS Composition object to get template.
        values
    :type composition: qgis.core.QgsLayout

    :return: Generated output path.
    :rtype: str