public static function load_template_with_dependencies(
        string $component,
        string $template,
        string $themename,
        bool $includecomments = false,
        string $lang = null
    ) {
        global $DB, $CFG, $PAGE;

        $params = self::validate_parameters(
            self::load_template_with_dependencies_parameters(),
            [
                'component' => $component,
                'template' => $template,
                'themename' => $themename,
                'includecomments' => $includecomments,
                'lang' => $lang
            ]
        );

        $loader = new mustache_template_source_loader();
        // Will throw exceptions if the template does not exist.
        $dependencies = $loader->load_with_dependencies(
            $params['component'],
            $params['template'],
            $params['themename'],
            $params['includecomments'],
            [],
            [],
            $params['lang']
        );
        $formatdependencies = function($dependency) {
            $results = [];
            foreach ($dependency as $dependencycomponent => $dependencyvalues) {
                foreach ($dependencyvalues as $dependencyname => $dependencyvalue) {
                    array_push($results, [
                        'component' => $dependencycomponent,
                        'name' => $dependencyname,
                        'value' => $dependencyvalue
                    ]);
                }
            }
            return $results;
        };

        // Now we have to unpack the dependencies into a format that can be returned
        // by external functions (because they don't support dynamic keys).
        return [
            'templates' => $formatdependencies($dependencies['templates']),
            'strings' => $formatdependencies($dependencies['strings'])
        ];
    }