/** * 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 coding_exception */ public function test_invalid_get_template_directories_for_component() { // Test something invalid. $dirs = mustache_template_finder::get_template_directories_for_component('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; }