Filters: FilterCodes

filter_filtercodes
Maintained by Picture of Michael MiletteMichael Milette
The FilterCodes filter enables Moodle content creators to easily customize and personalize site and course content using now over 115 plain text tags. Version 2.0 introduces almost 40% more FilterCodes including exciting new UI tags such as course lists as cards for your Front page, alert boxes, help and info popup windows and more which are compatible with most Boost based Moodle themes.
877 sites
1k downloads
55 fans
Moodle 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9

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

Here are just a few examples of the way you could use this plugin include:

  • Personalizing your course content with the learner's name and even their photo.
  • 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.
  • Display your list of available courses and categories on the Front page (Home page) as cards.
  • Display alert type boxes.
  • Create your own popup Help just like Moodle does (popup info icon also available)
  • Display the amount of disk space available to Moodle, number of courses, number of active students and more.
  • Display several pre-configured templates for use with the Contact Form plugin.
  • Add notes or reminders within your course content - which is only visible when editing the content.
  • Create dynamic and context aware custom menus for students, teachers, managers and administrators (only supported by a few themes unless you apply a patch).
  • Customize your dashboard with dynamic content.
  • Display course progress bar and percentage.
  • Easily display FontAwesome icons almost anywhere.
  • Display content from custom user and custom course fields in your course outline page. (useful for creating course templates for your organization).

Share with us how you use this plugin on your site.

Development efforts for this project are sponsored by the kind folks 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

  • [{ }] : You can escape tags so they are not processed by adding [brackets] around the tag. Can be disabled in the plugin's settings if it causes you problems.
  • [%7B %7D] : You can escape %7Bencoded%7D tags too so they are not processed by adding [brackets] around them.
  • {firstname} : Display the user's first name.
  • {surname} or {lastname} : 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 Moodle ID.
  • {idnumber} : Display the user's idnumber from their profile.
  • {username} : Display the user's username.
  • {userdescription} : Display the user's description.
  • {scrape url="..." tag="..." class="..." id="..." code="..."} : Scrapes the content from another web page. Must be enabled in FilterCodes settings.
  • {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.
  • {usercount} : Count total number of registered users on the site. Does not included deleted users, primary admin or guest.
  • {usersactive} : Count total number of registered users on the site. Does not included deleted users, disabled users, primary admin or guest.
  • {usersonline} : Total number of users who were online in the last 5 minutes.
  • {siteyear} : 4-digit current year.
  • {coursename} : Display the full name of the current course or the site name if not in a course.
  • {courseshortname} : Display the short name of the current course or the site short 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.
  • {coursecount} : Total number of courses on this Moodle site (not including Front Page).
  • {courseprogress}: (ALPHA) Displays course progress status in words. Only works within a course.
  • {courseprogressbar}: (ALPHA) Displays course progress status as a status bar. Only works within a course.
  • {coursecards}: (ALPHA) Display available courses as cards. Has only been tested on Front Page.
  • {categorycards}: (ALPHA) Display top level categories as cards. Has only been tested on Front Page.
  • {course_fields}: Displays the custom course fields. NOTE: Respects a custom course field's Visible To setting.
  • {course_field_shortname} : Display's custom course field. Replace "shortname" with the shortname of a custom course field all in lowercase. NOTE: Respects a custom course field's Visible To setting.
  • {courseimage} : Display's the course image.
  • {courseparticipantcount} : Displays the number of students enrolled in the current course.
  • {diskfreespace} : Display amount of free disk space for application folder.
  • {diskfreespacedata} : Display amount of free disk space for moodledata folder.
  • {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).
  • {categoryid} : If in a course, the ID of the course's parent category, the category ID of a course category page, otherwise 0.
  • {categoryname} : If in a course, the name of the course's parent category, otherwise blank.
  • {categorynumber} : If in a course, the number of the course's parent category, otherwise blank.
  • {categorydescription} : If in a course, the number of the description of a course's parent category, otherwise blank.
  • {categories} : Display an unordered list of links to all course categories.
  • {categoriesmenu} : A second level list of categories with links for use in custom menus (filtering must be supported by the theme).
  • {categories0} : Display an unordered list of just top level links to all course categories.
  • {categories0menu} : A second level list of just top level categories with links for use in custom menus (filtering must be supported by the theme).
  • {categoriesx} : Display an unordered list of other categories in the current category.
  • {categoriesxmenu} : A second level list of other categories in the current category 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.
  • {coursecontextid} or %coursecontextid%7D : Display a course's context ID.
  • {courseidnumber} : Display a course's ID number.
  • {sectionid} : Display the section ID (not to be confused with the section number).
  • {wwwroot} : Root URL of the Moodle site.
  • {wwwcontactform} : Action URL for Contact Form forms. (requires Contact Form plugin).
  • {pagepath} : Path of the current page without wwwroot.
  • {thisurl} : The complete URL of the current page.
  • {thisurl_enc} : The complete encoded URL of the current page.
  • {urlencode}{/urlencode} : URL encodes any content between the tages.
  • {referer} : Referring URL
  • {protocol} : http or https
  • {referrer} : Alias of {referer}
  • {ipaddress} : User's IP Address.
  • {sesskey} or %7Bsesskey%7D : Moodle session key.
  • {lang} : 2-letter language code of current Moodle language.
  • {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.
  • {getstring:component_name}stringidentifier{/getstring} or {getstring}stringidentifier{/getstring}: Display a Moodle language string in the current language. If no component name (plugin) is specified, will default to "moodle".
  • {toggleeditingmenu} : A Turn Editing On or Turn Editing Off custom menu item. Note that you need to add your own dash(es).
  • {editingtoggle} : "off" if in edit page mode. Otherwise "on". Useful for creating Turn Editing On/Off links.
  • {fa/fas/far/fal fa-...} : Insert FontAwesome icon. Note: FontAwesome Font/CSS must be loaded as part of your theme.
  • {glyphicon glyphicon-...} : Insert Glyphicons icon. Note: Glyphicons Font/CSS must be loaded as part of your theme.
  • {note}content{/note} : Enables you to include a note which will not be displayed.
  • {help}content{/help} : Enables you to create popup help icons just like Moodle does.
  • {info}content{/info} : Enables you to create popup help icons just like the popup Help icons but with an "i" information icon.
  • {highlight}{/highlight} : Highlight text. NOTE: Must only be used within a paragraph.
  • {profile_field_shortname} : Display's custom profile field. Replace "shortname" with the shortname of a custom profile field all in lowercase. NOTE: Will not display if custom profile field's settings are set to **Not Visible**.
  • {profilefullname}: Similar to {fullname} except that it displays a profile owner's name when placed on the Profile page.

Contact Form Templates (requires Contact Form Moodle plugin)

  • {formquickquestion} : Adds a "quick question" form to your course. Form includes Subject and Message fields. Note: User must be logged in or the form will not be displayed.
  • {formcontactus} : Adds a "Contact Us" form to your site (example: in a page). Form includes Name, Email address, Subject and Message fields.
  • {formcourserequest} : Adds a "Course Request" form to your site (example: in a page). Unlike Moodle's request-a-course feature where you can request to create your own course, this tag allows users to request that a course they are interested in be created. Could also be used to request to take a course. Form includes Name, Email address, Course name, Course Description.
  • {formsupport} : Adds a "Support Request" form to your site (example: in a page). Form includes Name, Email address, pre-determined Subject, specific Subject, URL and Message fields.
  • {formcheckin} : Adds a "I'm here!" button to your to your course. Form does not include any other fields. Note: User must be logged in or the button will not be displayed.

Conditionally display content

  • {ifloggedinas}{/ifloggedinas} : Will display the enclosed content only if you are logged-in-as (loginas) a different user.
  • {ifnotloggedinas}{/ifnotloggedinas} : Will display the enclosed content only if you are logged-in as yourself and not a different user.
  • {ifeditmode}{/ifeditmode} : Will display the enclosed content only if editing mode is turned on.
  • {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.
  • {ifdev}{/ifdev} : Will display the enclosed content only if the user is logged-in as an administrator and developer debugging mode is enabled.
  • {ifcustomrole roleshortname}{/ifcustomrole} : Will display enclosed content only if the user has the custom role specified by its shortname within the current context.
  • {ifnotcustomrole roleshortname}{/ifnotcustomrole} : Will display enclosed content only if the user does not have the custom role specified by its shortname within the current context.
  • {ifhome}{/ifhome} : Will display the enclosed content only if the user is on the Moodle Home Front Page.
  • {ifdashboard}{/ifdashboard} : Will display the enclosed content only if the user is on the Moodle Dashboard.
  • {ifincourse}{/ifincourse} : Will display the enclosed content only if the user is in a course other than the Front page.
  • {ifinsection}{/ifinsection} : Will display the enclosed content only if the user is in a section of a course which is not the Front Page.
  • {ifnotinsection}{/ifnotinsection} : Will display the enclosed content only if the user is not in a section of a course.
  • {ifcourserequests}{/ifcourserequests} : Will display enclosed contents only if the Request a Course feature is enabled.

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

HTML and language tagging

  • {-} : Is substituted for &shy;, a soft hyphen that only appears when needed.
  • {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} or {langx xx-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 localization information to apply a particular 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)
  • {details}{summary}{/summary}{/details} : An easy way to create an HTML 5 Details/Summary expandable section in your page. IMPORTANT: {details}{summary}{/summary} must all be on one line. The rest of the details can be on multiple lines followed by the {/details}. This is an experimental feature which may result in invalid HTML.

For more information and an up-to-date list of tags, see the documentation link.

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3

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 Georg Wiesinger
    Wed, Nov 15, 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, Nov 16, 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, Nov 16, 2017, 5:43 AM
    Hey, thanks, Michael! I just read your reply from October 17th!
  • Picture of Blair F.
    Thu, Nov 16, 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, Nov 16, 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, Nov 16, 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, Dec 19, 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, Dec 20, 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, Dec 21, 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, Mar 13, 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, Mar 31, 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, Apr 13, 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, Apr 13, 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.
  • Picture of pierre REMY
    Mon, Mar 30, 2020, 5:44 PM
    hi, what is the tag syntaxe to insert a user profil field ? i add in user profil, the new field "idwechat", id like to insert it. how do i do ?
  • Picture of Michael Milette
    Mon, Mar 30, 2020, 8:03 PM
    Hi Pierre, try {profile_field_shortname}. So, in your case, it would be {profile_field_idwechat}. If it doesn't work, you may need to update your plugin. For an up-to-date list of supported tags, remember to always take a look at the README.md file that came included with your FilterCodes plugin.

    There are lots of new tags coming in the next release of FilterCodes scheduled to launch at the same time as Moodle 3.9 in June 2020 including a new tag for custom course fields which may also be of interest to you. You can always try out the latest version available on Github by following the Source Control URL. Your feedback and suggestions are always welcome.
1 2
Please login to post comments