
FilterCodes
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).
- Conditionally display content depending on which cohort, group, role or Workplace tenant is looking at the content.
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.. Special thanks go out to several developers who have contributed to the development, documentation and testing of this release of FilterCodes, as well as to those who offered suggestions for several of the new tags. We appreciate your contributions!
Once installed and enabled, the following plain-text tags (no HTML required) will become available to you anywhere that Moodle supports filtering.
List of FilterCode tags
Creating FilterCodes Documentation
- [{ }] : 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.
Profile
- {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.
- {timezone} : Display the user's preferred timezone.
- {preferredlanguage} : Display the user's preferred language in that language. Because of this, it will be encapulated in an HTML span tag with an appropriately set lang attribute.
- {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.
- {webpage} : Display the user's webpage as seen in their profile.
- {institution} : Display the name of the institution from the user's profile.
- {department} : Display the name of the department from the user's profile.
- {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 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.
- {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.
- {firstaccessdate dateTimeFormat} : Date that the user first accessd the site. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
System Information
- {filtercodes} : Will display version and release of FilterCodes plugin. Not that this information is only available to those who can edit the tag.
- {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.
- {now dateTimeFormat} : Display's the current date. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
- {coursecount} : Total number of courses on this Moodle site (not including Front Page).
- {diskfreespace} : Display amount of free disk space for application folder. Infinite symbol will be displayed if greater than about 84,703.29 Yottabyte (YB) or failure to get size from operating system.
- {diskfreespacedata} : Display amount of free disk space for moodledata folder. Infinite symbol will be displayed if greater than about 84,703.29 Yottabyte (YB) or failure to get size from operating system.
- {wwwroot} : Root URL of the Moodle site.
UI Elements
- {coursecards}: (ALPHA) Display available courses as cards. Has only been tested on 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.
- {categorycards}: (ALPHA) Display top level categories as cards. Has only been tested on Front Page.
- {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.
- {alert style}content{/alert}: (ALPHA) Creates an alert box containing the specified content. You can change the style by specifying an optional parameter. Example:
{alert primary}
or{alert success}
. See List of styles.
For use in courses
- {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 dateTimeFormat} : Course start date. Will display "Open event" if there is no start date. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
- {courseenddate dateTimeFormat} : Course end date. Will display "Open event" if there is no end date. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
- {coursecompletiondate dateTimeFormat} : Course completion date. If not completed, will display "Not completed". Will also detect if completion is not enabled. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
- {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.
- {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.
- {coursesummary} : Display's the course summary. If placed in a site page, displays the site summary.
- {courseimage} : Display's the course image.
- {courseparticipantcount} : Displays the number of students enrolled in the current course.
- {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).
Also see Courses section below.
Categories
- {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.
- {categories0} : Display an unordered list of just top level links to all course categories.
- {categoriesx} : Display an unordered list of other categories in the current category.
Custom menu
- {categoriesmenu} : A second level list of categories with links for use in custom menus (filtering must be supported by the theme).
- {categories0menu} : A second level list of just top level categories with links for use in custom menus (filtering must be supported by the theme).
- {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).
- {toggleeditingmenu} : A Turn Editing On or Turn Editing Off custom menu item. Note that you need to add your own dash(es).
- {mycoursesmenu} : A second level list of courses with links for use in custom menus (filtering must be supported by the theme).
URL
- {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.
- {wwwcontactform} : Action URL for Contact Form forms. (requires Contact Form plugin).
Content
- {note}content{/note} : Enables you to include a note which will not be displayed.
- {highlight}{/highlight} : Highlight text. NOTE: Must only be used within a paragraph.
- {scrape url="..." tag="..." class="..." id="..." code="..."} : Scrapes the content from another web page. Must be enabled in FilterCodes settings.
- {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".
- {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.
- {mycourses} : Display an unordered list of links to all my enrolled courses
Contact Form templates
The following tags are replaced by Contact Form templates and therefore require that you have the Contact Form for Moodle plugin installed.
- {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.
Useful for creating Custom Contact Forms and Links
- {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.
- {editingtoggle} : "off" if in edit page mode. Otherwise "on". Useful for creating Turn Editing On/Off links.
- {wwwcontactform} : Action URL for Contact Form forms. (requires Contact Form plugin).
- {formsesskey} : Not a form. This can be used instead of having to insert the required hidden input field and JavaScript Snippet.
Conditionally display content filters (All versions of Moodle)
Note: {ifrolename
} and {ifminrolename
} type tags are based on role archetypes, not role shortnames. For example, you could have a role called students
but, if the archetype for the role is teacher
, the
role will be identified as a teacher
. Roles not based on archetypes will not with these tags.
Logged in/out
- {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.
- {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.
Courses
- {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.
- {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.
- {ifingroup id|idnumber}{/ifingroup} : Display content if the user is part of the specified course group ID or group ID number.
Roles
- {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.
- {ifminsitemanager}{/ifminsitemanager} : Will display the enclosed content only if the user is logged-in as a site manager or above.
- {ifadmin}{/ifadmin} : Will display the enclosed content only if the user is logged-in as an administrator.
- {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.
- {ifincohort CohortID|idnumber}{/ifincohort} : Will display enclosed content only if user is a member of the specified cohort. You can specify the Cohort ID in your cohort settings or its ID number. Cohort ID can contain a combination of letters from a to z, A to Z, numbers 0 to 9 and underscores. It will not work if it contains spaces, dashes or other special characters.
Miscellanious
- {ifdev}{/ifdev} : Will display the enclosed content only if the user is logged-in as an administrator and developer debugging mode is enabled.
- {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.
- {ifcourserequests}{/ifcourserequests} : Will display enclosed contents only if the Request a Course feature is enabled.
- {ifeditmode}{/ifeditmode} : Will display the enclosed content only if editing mode is turned on.
If the condition is not met in the particular context, the specified tag and it's content will be removed.
Conditionally display content filters (For Moodle Workplace)
- {iftenant idnumber|tenantid}{/iftenant} : (ALPHA) Will display the content if a tenant idnumber or tenant id is specified. Only {iftenant 1} will work in Moodle classic.
- {ifworkplace}{/ifworkplace} : (ALPHA) Will display the content only if displayed in Moodle Workplace.
HTML and "lang" tagging
- {-} : Is substituted for 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" xml: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 (it is ok if the line wraps). 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 but it works.
For more information and an up-to-date list of tags, see the documentation link.
Thanks & Regards
While FilterCodes certainly works in custom profile fields, unfortunately Moodle filters out the required HTML code needed to generate a Help (?) bubble. Here are a couple of tickets which might provide some alternatives if implemented in future releases of Moodle but its just not there yet today:
https://tracker.moodle.org/browse/MDL-70955 - Allow HTML in full Name of Custom User Profile Fields.
https://tracker.moodle.org/browse/MDL-56367 - Display description for custom user profile fields.
Alternatively, it might be possible to develop some JavaScript which would inject the help bubble HTML code into specific pages such as the Edit Profile and Registration page.
If you want to discuss this further, I strongly recommend that you bring it up in the Moodle discussion forums. Quote the ticket link for the solution you think would be best and also add comments and vote for that ticket. If there is enough show of support from people with similar needs, the feature will have a better chance of being implemented.
Best regards,
Michael Milette
If you need more help, please checkout the "More documentation on this plugin" link or ask your questions in the Discussion forums. Links to both of these are available on the FilterCodes plugin page on Moodle.org.
Best regards,
Michael Milette
Sincere Regards
I am glad to hear that you are enjoying FilterCodes. Thank you for taking the time to write to me about this issue. If you report it to https://github.com/michael-milette/moodle-filter_filtercodes/issues, I will definitely take a look at it and address it. Best regards,
Michael
I am wondering though if it is possible to use filter codes to display a custom checkbox or dropdown custom profile field so the user can edit the field from within an HTML block for example. I am trying to figure out a way for users to edit their custom profile field answers without having to dig into their user menu. I would use this in conjunction with a couple of auto plugins to be able to allow students to check a topic of study which would trigger the other plugins to auto enroll them in a cohort, and add a cohort based role for them, opening up access to various things on my moodle. It seems filter codes just displays the "answer" for the custom user profile field though, and not the entire field for editing... would you have any insights on how to accomplish what I'm asking?
Still a great and very useful plugin in many other areas of moodle though
I would like to know if there is any way to show the courses sorted by category. For example:
Category1
Course 1a
Course 1b
Category2
Course 2a
Course 2b
Thank you!