Filters: FilterCodes

filter_filtercodes
Maintained by Picture of Michael Milette Michael Milette
The FilterCodes filter enables Moodle content creators to easily customize and personalize site and course content using plain text tags.
247 sites
150 downloads
21 fans

The FilterCodes plugin for Moodle enables you to insert plain text tags like {firstname} into your Moodle site or course content in order to to personalize the site to the individual students.

Examples uses for this plugin include:

  • Personalizing course content.
  • Display certain content depending on the user's role.
  • Conditionally display content depending on whether the user is enrolled in the current course.
  • Create links that normally require the users ID as part of the URL.
  • Insert default user information into Contact Form for Moodle forms.
Share with us how you use this plugin on your site.

The work for this project was sponsored by the kind folk at TNG Consulting Inc..

Once installed and enabled, the following plain-text tags (no HTML required) will become available to you anywhere that Moodle supports filtering:


Moodle metadata filters

  • {firstname} : Display the user's first name.
  • {surname} : Display the user's surname (family/last name).
  • {fullname} : Display the user's first name and surname.
  • {alternatename} : Display the user's alternate name. If blank, will display user's first name instead.
  • {city} : Display the user's city.
  • {country} : Display the user's country.
  • {email} : Display the user's email address.
  • {userid} or %7Buserid%7D : Display the user's ID.
  • {username} : Display the user's username.
  • {userpictureurl X} : Display the user's profile picture URL. X indicates the size and can be sm (small), md (medium) or lg (large). If the user does not have a profile picture or is logged out, the default faceless profile photo URL will be shown instead.
  • {userpictureimg X} : Generates an <img> html tag containing the user's profile picture. X indicates the size and can be sm (small), md (medium) or lg (large). If the user does not have profile picture or is logged out, the default faceless profile photo will be used instead.
  • {coursename} : Display the name of the current course or the site name if not in a course.
  • {coursestartdate} : Course start date. Will display "Open event" if there is no start date.
  • {courseenddate} : Course end date. Will display "Open event" if there is no end date.
  • {coursecompletiondate} : Course completion date. If not completed, will display "Not completed". Will also detect if completion is not enabled.
  • {mycourses} : Display an unordered list of links to all my enrolled courses.
  • {mycoursesmenu} : A second level list of courses with links for use in custom menus (filtering must be supported by the theme).
  • {categories} : Display an unordered list of links to all course categores.
  • {categoriesmenu} : A second level list of categories with links for use in custom menus (filtering must be supported by the theme).
  • {institution} : Display the name of the institution from the user's profile.
  • {department} : Display the name of the department from the user's profile.
  • {courseid} or %7Bcourseid%7D : Display a course's ID.
  • {wwwroot} : Display the root URL of the Moodle site.
  • {protocol} : http or https
  • {referrer} : Referring URL
  • {ipaddress} : User's IP Address.
  • {sesskey} or %7Bsesskey%7D : Moodle session key.
  • {recaptcha} : Display the ReCAPTCHA field - for use with Contact Form for Moodle. Note: Will be blank if user is logged-in using a non-guest account.
  • {readonly} : To be used within form input fields to make them read-only if the user is logged-in.

Conditionally display content filters

  • {ifenrolled}{/ifenrolled} : Will display the enclosed content only if the user is enrolled in the current course.
  • {ifnotenrolled}{/ifnotenrolled} : Will display the enclosed content only if the user is not enrolled in the current course.
  • {ifloggedin}{/ifloggedin} : Will display the enclosed content only if the user is logged in as non-guest.
  • {ifloggedout}{/ifloggedout} : Will display the enclosed content only if the user is logged out or is loggedin as guest.
  • {ifguest}{/ifguest} : Will display the enclosed content only if the user is logged-in as guest.
  • {ifstudent}{/ifstudent} : Will display the enclosed content only if the user is logged-in and enrolled in the course (no other roles).
  • {ifassistant}{/ifassistant} : Will display the enclosed content only if the user is logged-in as a non-editing teacher in the current course.
  • {ifminassistant}{/ifminassistant} : Will display the enclosed content only if the user is logged-in as a non-editing teacher or above in the current course.
  • {ifteacher}{/ifteacher} : Will display the enclosed content only if the user is logged-in as a teacher in the current course.
  • {ifminteacher}{/ifminteacher} : Will display the enclosed content only if the user is logged-in as a teacher or above in the current course.
  • {ifcreator}{/ifcreator} : Will display the enclosed content only if the user is logged-in as a course creator.
  • {ifmincreator}{/ifmincreator} : Will display the enclosed content only if the user is logged-in as a course creator or above.
  • {ifmanager}{/ifmanager} : Will display the enclosed content only if the user is logged-in as a manager.
  • {ifminmanager}{/ifminmanager} : Will display the enclosed content only if the user is logged-in as a manager or above.
  • {ifadmin}{/ifadmin} : Will display the enclosed content only if the user is logged-in as an administrator.

If the condition is not met in the particular context, the specified tag and it's content will be removed.

HTML and language tagging

  • {nbsp} : Is substituted for a non-breaking space when displayed.
  • {langx xx}{/langx} : Tag specific text in a particular language by wrapping the text in a plain text pair of {langx xx} {/langx} tags. This makes no visible changes to the content but wraps the content in an HTML <span lang="xx"></span> inline tag. As a result, screen readers will make use of this information to use a particular kind of pronunciation if the text is in a different language than the language of the rest of the page. This is required for compliance with W3C Web Content Accessibility Guidelines (WCAG 2.0)

For more information, see the documentation link.

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2

Contributors

Picture of Michael Milette
Michael Milette (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Ralf Hilgenstock
    Mon, 13 Nov 2017, 4:46 PM
    Thanks great tool. Can you check the lang file. There are four empty strings.
  • Picture of Michael Milette
    Mon, 13 Nov 2017, 10:44 PM
    Hi Ralf,

    Thank you for bringing this up. Nice to know people check my work. These are actually empty/blank by design. Most people will not want to put anything in these fields.

    They are for special situations where a user is not logged into your website but you still want them to have a first, last name, username and email address. I can't think of a situation like that but they are available just in case. You'll find more information on this in the FAQ section of documentation. See:

    https://github.com/michael-milette/moodle-filter_filtercodes#when-a-user-is-logged-out-the-first-name-surname-full-name-email-address-and-username-are-empty-how-can-i-set-default-values-for-these-tags
  • Picture of Georg Wiesinger
    Wed, 15 Nov 2017, 3:33 PM
    Good morning,

    I noticed that the latest version 0.4.2 with the fixed https ReCPATCHA issue is only available via Github.

    Kind regards,
    George
  • Picture of Michael Milette
    Thu, 16 Nov 2017, 12:46 AM
    Oh darn! Sorry about that George. Looks like I uploaded the old version (with the new release notes) instead of the latest version. Thanks for letting me know. I've updated it on Moodle.org.
  • Picture of Blair F.
    Thu, 16 Nov 2017, 5:43 AM
    Hey, thanks, Michael! I just read your reply from October 17th!
  • Picture of Blair F.
    Thu, 16 Nov 2017, 6:03 AM
    I think this is one of the most awesome plugins! I hope you continue to support it forever!
  • Picture of genaguerry3320 genaguerry3320
    Thu, 16 Nov 2017, 8:58 PM
    Hi Bert, thanks! Glad you wish it. it's unfortunate that there's a conflict with easy Certificate, another nice plugin I've used myself on many Moodle sites. Do take a glance at the bug huntsman wherever I actually have planned an answer. As for obtaining it into Quickmail and electronic communication too, it is a Moodle filter. If the plugins build use of format_text() and format_string() functions, FilterCodes can work. It's up to the author of the plugins to use the functions.check itemguides.com
    You will get your answer.
  • Picture of Michael Milette
    Thu, 16 Nov 2017, 11:20 PM
    Why thank you Blair, that is so kind of you. I love working with Moodle and people like you and have every intention to continue the work I have started well into the future.
  • Picture of Kees Koopman
    Tue, 19 Dec 2017, 8:48 PM
    Hi,
    This is a great plug-in! Thanks!

    Is it possible to add a filtercode, such as: "IfMemberOfGroup xxx} and {/IfMemberOfGroup} (where XXX is the group-id)

    That would be very nice!

  • Picture of Michael Milette
    Wed, 20 Dec 2017, 4:41 AM
    Hi Kees,

    Great suggestion for a new tag! It should be possible. Just go to the Bug Issue Tracker at https://github.com/michael-milette/moodle-filter_filtercodes/issues and add your suggestion for the new tag. Use the subject line with "Feature request: {ifmemberofgroup}". I will also need you to include a detailed example of how you might want to use this feature.

    I can't make any promises but I will see if I can get it into the next release scheduled for May, around the same time as Moodle 3.5. If you need it sooner, you can submit a pull request. I am also available for hire.

    Thanks again for taking the time to write. I really appreciate it.

    Best regards,

    Michael
  • Picture of Kees Koopman
    Thu, 21 Dec 2017, 11:17 PM
    Hi Michael,

    Thanks for your quick response.
    I have made a feature request.

    In case you were going to program these weeks, it would be cool if this request can be granted smile.
    And otherwise I will wait until May 2018 smile.

    Thank you very much for this plug-in! This makes Moodle a whole lot more 'personal'.

    Sincerely,
    Kees Koopman.
  • Picture of Bas Harkink
    Tue, 13 Mar 2018, 5:53 PM
    Hello All,

    Recently I asked Michael a few questions about this amazing plugin! I was trying to make the filter codes work in the custom menu. Sadly the plugin didn’t seem to work and I didn’t see why it was not working. Since i asked Michael in a PM, my question and the response are not listed here:

    My question:

    I am trying to use it to make custom admin menu items that only show for admins. To do this I am adding the codes you have given us in the documentation: https://github.com/michael-milette/moodle-filter_filtercodes/blob/dev050/README.md#usage

    Am i doing something wrong?

    ~~~~~~~~~~~~~~~

    Michaels response:

    Many Moodle Themes don't support filters in the custom menu. In order to enable support, you will need to add the code provided in the FAQ section of the
    documentation for the FilterCodes plugin.

    To enable filter support for custom menus, see: https://github.com/michael-milette/moodle-filter_filtercodes/blob/master/README.md#can-i-use-filtercodes-in-custom-menus

    As you are using the Boost theme, be sure to follow the instructions for themes based on boost, not for themes based on bootstrap. Note: If you make the change to the core Moodle theme instead of a child theme, you may need to remember to re-apply the change if you upgrade to a newer version of Moodle in the future.

    As for your tags, if you just want your menu to show up for Administrators, the following will do:

    {IFADMIN}ADMIN{/IFADMIN}

    If you want it to appear for both Managers and Administrators, then use:

    {IFMINMANAGER}ADMIN{/IFMINMANAGER}

    In fact, you could put your whole menu inside the tags. There are examples of how to do this in the documentation as well. See: https://github.com/michael-milette/moodle-filter_filtercodes/blob/dev050/README.md#filtercodes-in-a-custom-menu

    In that example, the only reason that I have both {IFMINMANAGER} and {IFADMIN} tags is because I wanted to demonstrate that you can create an admin menu that would be available to Managers and Admins, but with certain options only available to admins.
  • Picture of Michael Milette
    Sat, 31 Mar 2018, 3:53 AM
    An updated version of the Contact Form for Moodle plugin as well as the FilterCodes plugin is now available. The new versions will automatically detect and use reCAPTCHA v2 when installed on Moodle 3.1.11+, 3.2.8+, 3.3.5+, 3.4.5+ and of course 3.5+. If you are using reCAPTCHA with Contact Form for Moodle, you must upgrade both of the plugins as soon as possible.
  • Picture of Alex Sandu
    Fri, 13 Apr 2018, 3:17 PM
    In some activities, "dataform view" in my case, a URL that contains { and } is changed automatically into %7B and %7D

    For example: https://www.somesite.com/report/progress/index.php?course={courseid}
    it's turned into: https://www.somesite.com/report/progress/index.php?course=%7Bcourseid%7D

    You should also check for these "malformed" URL.
  • Picture of Michael Milette
    Fri, 13 Apr 2018, 8:55 PM
    Hi Alex, thank you for bringing this to my attention. Please report this using the Bug Tracker link on the FilterCodes plugin page at Moodle.org and I will make sure it gets into the next release of FilterCodes coming out soon. Please also let me know if you notice this issue with other types of activities or resources.
1 2
Please login to post comments