Skip to content

Commit 9af0934

Browse files
committed
Add check on overrides/ folder in templates processing - refs #2156
1 parent fbe1e9f commit 9af0934

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

main/inc/lib/template.lib.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,24 @@ public function set_header($status)
446446
}
447447

448448
/**
449-
* If template not found in custom template folder, the default template
450-
* will be used.
449+
* Returns the sub-folder and filename for the given tpl file.
450+
* If template not found in overrides/ or custom template folder, the
451+
* default template will be used.
451452
* @param string $name
452453
*
453454
* @return string
454455
*/
455456
public function get_template($name)
456457
{
458+
// Check if the tpl file is present in the main/template/overrides/ dir
459+
// Overrides is a special directory meant for temporary template
460+
// customization. It must be taken into account before anything else
461+
$file = api_get_path(SYS_CODE_PATH).'template/overrides/'.$name;
462+
if (is_readable($file)) {
463+
return 'overrides/'.$name;
464+
}
465+
// If a template folder has been manually defined, search for the right
466+
// file, and if not found, go for the same file in the default template
457467
if ($this->templateFolder != 'default') {
458468
// Avoid missing template error, use the default file.
459469
$file = api_get_path(SYS_CODE_PATH).'template/'.$this->templateFolder.'/'.$name;
@@ -466,7 +476,9 @@ public function get_template($name)
466476
}
467477

468478
/**
469-
* Set course parameters
479+
* Prepare the _c array for template files. The _c array contains
480+
* information about the current course
481+
* @return void
470482
*/
471483
private function set_course_parameters()
472484
{
@@ -494,7 +506,10 @@ private function set_course_parameters()
494506
}
495507

496508
/**
497-
* Set user parameters
509+
* Prepare the _u array for template files. The _u array contains
510+
* information about the current user, as returned by
511+
* api_get_user_info()
512+
* @return void
498513
*/
499514
private function set_user_parameters()
500515
{

0 commit comments

Comments
 (0)