Add Comments to Moodle Sites

With FastComments and a little programming know-how, we can add live commenting, with SSO, to the course page of any Moodle site!

Moodle Example

Since we'll use SSO, your users won't have to login separately to comment. They will use their Moodle account seamlessly.

If you don't feel comfortable with the following tutorial, reach out to support, and we may be able to help set it up for you.

Step 1: Get Server Access Internal Link

First off, you'll need to get SSH access to your Moodle server.

Once you have SSH access, and you have access to a shell, continue to step 2.

Step 2: Identify View File Internal Link

Next we need to identify the view.php. This will probably be in a directory like /var/www/html/moodle/mod/book/view.php.

Once you find this file, let's back it up before moving on: sudo cp /var/www/html/moodle/mod/book/view.php /var/www/html/moodle/mod/book/view.php.bak.

If your site breaks during this tutorial, we can restore it via the command: sudo cp /var/www/html/moodle/mod/book/view.php.bak /var/www/html/moodle/mod/book/view.php.

Step 3: Add Code Internal Link

Next, open the view.php file. You can do this with nano:

sudo nano /var/www/html/moodle/mod/book/view.php

Use the arrow keys to scroll down to the bottom. Look for some text that says something like:

echo $OUTPUT->box_end();

Now let's copy the code that adds the comment widget:

Moodle Comments Code
Copy Copy
3if ($id) {
4 $url_decoded = str_replace('&', '&', $PAGE->url);
5 $users_picture_obj = new user_picture($USER);
6 $users_picture_url = $users_picture_obj->get_url($PAGE);
8 $simple_sso_json = json_encode($USER && $USER->username !== 'guest' ? array(
9 "username" => $USER->firstname . $USER->lastname,
10 "email" => $USER->email,
11 "avatar" => $users_picture_url->out(false)
12 ) : array(
13 "loginURL" => '/login/index.php'
14 ));
16 echo "<script src=\"\"></script>
17 <div id=\"fastcomments-widget\"></div>
18 <script>
19 FastCommentsUI(document.getElementById('fastcomments-widget'), {
20 tenantId: 'demo',
21 simpleSSO: $simple_sso_json,
22 urlId: $id,
23 url: '$url_decoded'
24 });
25 </script>";

Use the arrow keys to position your cursor before the "box_end" line, and paste.

You should have something like this:

Moodle Example

Now save:

  1. Press ctrl+x
  2. Press y
  3. Press enter

That's it!

Member Site Success Internal Link

That's it! You should now have live commenting added to your Moodle site.

If you've run into a permission denied error, or would like to customize FastComments, read on.

Member Site Customization Internal Link

FastComments is designed to be customized to match your site.

If you'd like to add custom styling, or tweak configuration, Checkout our Customization Documentation to learn how.

Want a Dedicated Plugin? Internal Link

If you like FastComments and would like to see a dedicated Moodle plugin, hit the heart button in the bottom right so that we know there is demand for a dedicated plugin.

Until then, we will maintain this documentation.