*
* @param string $component Filter the list to a single component.
* @param string $search Search string to optionally filter the list of templates.
+ * @param string $themename The name of the current theme.
* @return array[string] Where each template is in the form "component/templatename".
*/
public static function list_templates($component = '', $search = '', $themename = '') {
$templatedirs = array();
$results = array();
- if ($component != '') {
+ if ($component !== '') {
// Just look at one component for templates.
$dirs = mustache_template_finder::get_template_directories_for_component($component, $themename);
$string['all'] = 'All components';
$string['component'] = 'Component';
-$string['coresubsystem'] = 'Core subsystem ({$a})';
+$string['coresubsystem'] = 'Subsystem ({$a})';
$string['documentation'] = 'Documentation';
$string['example'] = 'Example';
$string['noresults'] = 'No results';
$templatename = $component . '/' . $template;
// Will throw exceptions if the template does not exist.
- $filename = mustache_template_finder::get_template_filename($templatename, $themename);
+ $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.
- * Use the leading component to restrict us specific directories.
+ * 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_filename($name);
+ return mustache_template_finder::get_template_filepath($name);
}
}
/**
* Helper function for getting a list of valid template directories for a specific component.
*
- * @param string $component
- *
+ * @param string $component The component to search
+ * @param string $themename The current theme name
* @return string[] List of valid directories for templates for this compoonent. Directories are not checked for existence.
*/
public static function get_template_directories_for_component($component, $themename = '') {
$dirs = array();
$compdirectory = core_component::get_component_directory($component);
if (!$compdirectory) {
- throw new coding_exception("Component was not valid:" . s($component));
+ throw new coding_exception("Component was not valid: " . s($component));
}
// Find the parent themes.
* Helper function for getting a filename for a template from the template name.
*
* @param string $name - This is the componentname/templatename combined.
- *
+ * @param string $themename - This is the current theme name.
* @return string
*/
- public static function get_template_filename($name, $themename = '') {
+ public static function get_template_filepath($name, $themename = '') {
global $CFG, $PAGE;
if (strpos($name, '/') === false) {
throw new coding_exception('Templates names must be specified as "componentname/templatename"' .
- ' (' . $name . ' requested) ');
+ ' (' . s($name) . ' requested) ');
}
list($component, $templatename) = explode('/', $name, 2);
$component = clean_param($component, PARAM_COMPONENT);
if (strpos($templatename, '/') !== false) {
- throw new coding_exception('Templates cannot be placed in sub directories (' . $name . ' requested)');
+ throw new coding_exception('Templates cannot be placed in sub directories (' . s($name) . ' requested)');
}
$dirs = self::get_template_directories_for_component($component, $themename);
$dirs = mustache_template_finder::get_template_directories_for_component('octopus', 'clean');
}
- public function test_get_template_filename() {
+ public function test_get_template_filepath() {
global $CFG;
- $filename = mustache_template_finder::get_template_filename('core/pix_icon', 'clean');
+ $filename = mustache_template_finder::get_template_filepath('core/pix_icon', 'clean');
$correct = $CFG->dirroot . '/lib/templates/pix_icon.mustache';
$this->assertSame($correct, $filename);
}
/**
* @expectedException moodle_exception
*/
- public function test_invalid_get_template_filename() {
+ public function test_invalid_get_template_filepath() {
// Test something invalid.
- $dirs = mustache_template_finder::get_template_filename('core/octopus', 'clean');
+ $dirs = mustache_template_finder::get_template_filepath('core/octopus', 'clean');
}
}