Moodle plugins directory: Use template on course creation | Moodle.org
Use template on course creation
This local plugin allows site administrators to create "template" courses which will be restored into new courses on course creation. The intended use case is defining common blocks and activities for a given academic term.
Usage
The administrator will need to create a "template" course which contains the desired blocks and resources. This course will need a specially-named short name. By default the plugin will search for a course with the short name Template-[TERMCODE], where [TERMCODE] is the matching value for YYYYYY. For example, if a course had the termcode 201610, the module would search for a course with the short name Template-201610.
The administrator will need to define a regular expression for extracting the term code from the course idnumber. This will be used to identify which course template (if any) should be used on creation. For example, if your courses have idnumbers in the format XXXXXX.YYYYYY, where YYYYYY is the termcode, then the regular expression /[0-9]+\.([0-9]+)/ will return YYYYYY.
The plugin listens on the \core\event\course_created event and fires immediately on course creation. Once you've given a course the necessary short name you don't need to do anything further. The plugin will create a backup of the template course and import it into the new course.
You should consider overriding Moodle's default block settings in config.php: $CFG->defaultblocks_override = '';. Otherwise you will get two sets of blocks on course creation. Manually configure the blocks in the template course instead.
I am trying to get this plugin to work, but it has thus far not done anything for me. The plugin has installed correctly, and I can find its details in Local Plugins/Use template on course creation. I have set the term code to /^[^\d]*(\d+)/ and the shortname format to Template-[TERMCODE]
I have created a template in the Miscelaneous category. It is titled "Certificate Template", has the shortname "Template-1", and includes a forum activity and a standard block.
I create a new course in a separate category with a title of, let's say "foo" and a shortname of "bar". Its idea is "1-002-02". The regex code should return a "1" in this situation. However, when I view my created course, it does not look like it fits the template I created. Does anyone know why this has happened?
Best regards,
Mable Simons
Charles
I tried using your supplied regex, but the plugin still doesn't work. I have also tried other regex codes I found through Google (Stackexchange). I don't believe the regex is the issue here. Any other ideas what may be wrong?
Mable Simons
Course short names are as follows:
SUBJ--NUM_YYYY-TT_SEC (ENG--900_2017-SP_01 as an example)
Current term extraction pattern:
/([0-9]+\-[A-Z]+)/ (should return 2017-SP for the example course short name above)
Template name format:
Template-[TERMCODE]
Template Course Name:
Template-2017-SP
So if I create a test course with the short name ENG--900_2017-SP_01, it does not seem to be triggering the automatic restore from the template. Any thought as to what might be wrong? Maybe the regex?
Charles
You could try:
/().*/
This will (I think) match every ID and return an empty string. You should then give your template course a shortname of "template-".
/(?<=\_)(.*?)(?=\-)/