public static function get_fragment($component, $callback, $contextid, $args = null) {
        global $OUTPUT, $PAGE;

        $params = self::validate_parameters(self::get_fragment_parameters(),
                array(
                    'component' => $component,
                    'callback' => $callback,
                    'contextid' => $contextid,
                    'args' => $args
                )
        );

        // Reformat arguments into something less unwieldy.
        $arguments = array();
        foreach ($params['args'] as $paramargument) {
            $arguments[$paramargument['name']] = $paramargument['value'];
        }

        $context = context::instance_by_id($contextid);
        self::validate_context($context);
        $arguments['context'] = $context;

        // Hack alert: Set a default URL to stop the annoying debug.
        $PAGE->set_url('/');
        // Hack alert: Forcing bootstrap_renderer to initiate moodle page.
        $OUTPUT->header();

        // Overwriting page_requirements_manager with the fragment one so only JS included from
        // this point is returned to the user.
        $PAGE->start_collecting_javascript_requirements();
        $data = component_callback($params['component'], 'output_fragment_' . $params['callback'], array($arguments));
        $jsfooter = $PAGE->requires->get_end_code();
        $output = array('html' => $data, 'javascript' => $jsfooter);
        return $output;
    }