/** * Return a mustache template, and all the strings it requires. * * @param string $component The component that holds the template. * @param string $templatename The name of the template. * @param string $themename The name of the current theme. * @return string the template */ public static function load_template($component, $template, $themename) { global $DB, $CFG, $PAGE; $params = self::validate_parameters(self::load_template_parameters(), array('component' => $component, 'template' => $template, 'themename' => $themename)); $component = $params['component']; $template = $params['template']; $themename = $params['themename']; $templatename = $component . '/' . $template; // Will throw exceptions if the template does not exist. $filename = mustache_template_finder::get_template_filepath($templatename, $themename); $templatestr = file_get_contents($filename); return $templatestr; }
/** * Helper function for getting a Mustache template file name. * Uses the leading component to restrict us specific directories. * * @param string $name * @return string Template file name */ protected function getFileName($name) { // Call the Moodle template finder. return mustache_template_finder::get_template_filepath($name); }
/** * Return a mustache template. * Note - this function differs from the function core_output_load_template * because it will never return a theme overridden version of a template. * * @param string $component The component that holds the template. * @param string $template The name of the template. * @return string the template or false if template doesn't exist. */ public static function load_canonical_template($component, $template) { // Get the list of possible template directories. $dirs = mustache_template_finder::get_template_directories_for_component($component); $filename = false; $themedir = core_component::get_plugin_types()['theme']; foreach ($dirs as $dir) { // Skip theme dirs - we only want the original plugin/core template. if (strpos($dir, $themedir) === 0) { continue; } $candidate = $dir . $template . '.mustache'; if (file_exists($candidate)) { $filename = $candidate; break; } } if ($filename === false) { // There are occasions where we don't have a core template. return false; } $templatestr = file_get_contents($filename); return $templatestr; }
/** * @expectedException moodle_exception */ public function test_invalid_get_template_filepath() { // Test something invalid. $dirs = mustache_template_finder::get_template_filepath('core/octopus', 'clean'); }
/** * Return a mustache template. * Note - this function differs from the function core_output_load_template * because it will never return a theme overridden version of a template. * * @param string $component The component that holds the template. * @param string $template The name of the template. * @return string the template */ public static function load_canonical_template($component, $template) { // Get the list of possible template directories. $dirs = mustache_template_finder::get_template_directories_for_component($component); $filename = false; foreach ($dirs as $dir) { // Skip theme dirs - we only want the original plugin/core template. if (strpos($dir, "/theme/") === false) { $candidate = $dir . $template . '.mustache'; if (file_exists($candidate)) { $filename = $candidate; break; } } } if ($filename === false) { throw new moodle_exception('filenotfound', 'error'); } $templatestr = file_get_contents($filename); return $templatestr; }