Moodle | Hyperlinks in course summary

| By Webner

In Moodle when we create a new course we have an option to add summary/description of course. We can use this summary anywhere while showing courses. This summary could be anything. It can be simple text, image, multimedia or hyperlinks.

Hyperlinks are 2 forms:

Hyperlink launches a web page: Eg
Hyperlink launches a document that is in file repository
These links are in the form of @@PLUGINFILE@@.
For Example: “@@PLUGINFILE@@/CPE%20Credit%20Training.pdf”:




Issue: When there are @@PLUGINFILE@@ hyperlinks present in course summary that should launch a document that is in the file repository we get an error i.e
Not Found
The requested URL /my/@@PLUGINFILE@@/CPE Credit Training.pdf was not found on this server.
Apache/2.2.15 (CentOS) Server at Port 434

Solution: To launch correct document we need to convert these urls in real url using file_rewrite_pluginfile_urls() of lib/filelib.php.

$url = file_rewrite_pluginfile_urls($url, 'pluginfile.php',
$context->id, 'mod_mymodule', 'proper_file_area', $itemid);

File_rewrite_pluginfile_urls is used to Convert encoded URLs in $text from the @@PLUGINFILE@@/… form to an actual URL.


Pluginfile.php – The script that should be used to serve these files
$context->id – context id for an activity, can be determined by context_module::instance($cmid).
If we don’t have $cmid it can be found
by $cm = get_coursemodule_from_instance(‘data’, $dataid) .

‘Mod_mymodule’ – This parameter defines the name of the module of which summary is associated (like course)

‘Proper_file_area’ – This parameter identifies the file area to use that is the name that the xyz module has chosen to use for this particular file area.

itemid (if used) – whatever id number is relevant to the particular file area you are using (it is your choice as to what to use this number for)

For Example:

$url=url in @@PLUGINFILE@@ form.
$finaltext = file_rewrite_pluginfile_urls($url, 'pluginfile.php',courseid, 'course', 'draft', Null);

It will convert url to something like this:


  1. Hi I would like to ask where do I need to put the code? Basically I would like to have a correct path of image when I embed it in the course summary page.

    Thank you

  2. This code needs to be placed according to the requirements. For example, to show the course summary on the front page or dashboard we can use this code in frontpage.php of the theme.

Leave a Reply

Your email address will not be published. Required fields are marked *