Moodle plugins directory: FilterCodes | Moodle.org
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 individual students.
Here are just a few examples of the ways you could use this plugin include:
- Personalize 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 user's 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, the number of courses, the 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 the custom user and custom course fields on your course outline page. This can be 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.
- Insert support information in every course and manage that information centrally.
- Easily list teachers, and non-editing teachers (assistants) in your course.
- Create buttons and charts.
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 many of the new tags. We appreciate your contributions!
Useful links
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} : Displays the user's first name.
- {surname} or {lastname} : Displays the user's surname (family/last name).
- {fullname} : Displays the user's first name and surname.
- {alternatename} : Displays the user's alternate name. If blank, will display the user's first name instead.
- {city} : Displays the user's city.
- {country} : Displays the user's country.
- {timezone} : Displays the user's preferred time zone.
- {preferredlanguage} : Displays the user's preferred language in that language. Because of this, it will be encapsulated in an HTML span tag with an appropriately set lang attribute.
- {email} : Displays the user's email address.
- {userid} or %7Buserid%7D : Displays the user's Moodle ID.
- {idnumber} : Displays the user's id number from their profile.
- {username} : Displays the user's username.
- {userdescription} : Display the user's description.
- {webpage} : Displays the user's webpage as seen in their profile.
- {institution} : Displays the name of the institution from the user's profile.
- {department} : Displays the name of the department from the user's profile.
- {userpictureurl X} : Displays 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 a profile picture or is logged out, the default faceless profile photo will be used instead.
- {profile_field_shortname} : Display the content of a custom profile field. Replace "shortname" with the shortname of a custom profile field all in lowercase. NOTE: Will not display if the 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 accessed the site. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
- {lastlogin dateTimeFormat} : Date/Time that you last logged into the site.
System Information
- {filtercodes} : Will display the version and release of FilterCodes plugin. Not that this information is only available to those who can edit the tag.
- {usercount} : Count the total number of registered users on the site. Does not include deleted users, primary admin or guests.
- {usersactive} : Count the total number of registered users on the site. Does not include deleted users, disabled users, primary admin or guests.
- {usersonline} : Total number of users who were online in the last 5 minutes.
- {siteyear} : 4-digit current year.
- {now dateTimeFormat} : Display 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} : Displays the amount of free disk space for the application directory. An infinite symbol will be displayed if greater than about 84,703.29 Yottabyte (YB) or if it fails to get the size from the operating system.
- {diskfreespacedata} : Displays the amount of free disk space for moodledata directory. An infinite symbol will be displayed if greater than about 84,703.29 Yottabyte (YB) or if it fails to get the size from the operating system.
- {wwwroot} : Root URL of the Moodle site.
- {userscountrycount} : Total number of countries that users are from according to their profile.
-
{supportname} : Support name as seen on Site Administration > Server > Support contact.
-
{supportemail} : Support email address as seen on Site Administration > Server > Support contact.
-
{supportpage} : Support page URL as seen on Site Administration > Server > Support contact.
-
{supportservicespage} : Support services page URL as seen on Site Administration > Server > Support contact in Moodle LMS 4.2 and later.
UI Elements
-
{coursecard id} : (ALPHA) Displays an individual course card.
-
{coursecards} : (ALPHA) Displays available courses as cards. Has only been tested on Front Page.
- {coursecards id} : (ALPHA) Same as {coursecards} but you can specify the top-level category ID number to be displayed.
- {courseprogress} : (ALPHA) Displays course progress status in words. Only works within a course.
-
{courseprogresspercent}: Displays course progress percentage as a number without a percentage symbol. 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.
- {courserequest}: Display a Request a Course link.
- {chart pie}: (ALPHA) : Display a 2-section pie chart.
- {chart progressbar} : (ALPHA) Displays a progress bar.
- {chart progresspie} : (ALPHA) Create a (circle / doughnut) progress chart.
- {chart radial} : (ALPHA) Displays a radial chart.
- {button url}Label{/button} : Displays link as a button.
- {hr} : Displays a horizontal rule line.
- {label backgroundtype}{/label} : Displays text over a colour background.
- {markborder}{/markborder} : Surrounds text with a red dashed border.
- {marktext}{/marktext} : Highlight text using HTML5's mark tag.
- {qrcode}{/qrcode} : Generates and displays a QR Code for the content between the tags.
- {showmore}{/showmore} : (ALPHA) Toggle showing content between opening and closing more tags.
- {mycoursescards} : Displays a series of cards for my enrolled courses.
- {teamcards} : Displays photos, names (optionally linked) and optional descriptions of the users who are teachers. Great for Faculty pages.
For use in courses
- {coursename} : Displays the full name of the current course or the site name if not in a course.
- {courseshortname} : Displays the short name of the current course or, if not in a course, the site's short name.
- {courseenrolmentdate dateTimeFormat} : Date and time at which the user was enrolled in the current course. For information on the optional dateTimeFormat format, see Supported dateTimeFormats Formats in the FAQ section of the documentation.
- {coursestartdate dateTimeFormat} : Course start date. Displays "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. Displays "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.
- {courseprogressbar}: (ALPHA) Displays course progress status as a status bar.
- {course_fields}: Displays the custom course fields. NOTE: Respects a custom course field's Visible To setting.
- {course_field_shortname} : Displays custom course field. Replace "shortname" with the short name of a custom course field all in lowercase. NOTE: Respects a custom course field's Visible To setting.
- {coursesummary} : Displays the course summary. If placed on a site page, displays the site summary.
- {courseimage} : Displays the course image.
- {courseimage-url} : URL of the course image.
- {courseparticipantcount} : Displays the number of students enrolled in the current course.
- {courseid} or %7Bcourseid%7D : Displays a course's ID.
- {coursecontextid}: Displays a course's context ID.
- %7Bcoursecontextid%7D : Displays a course's context ID - for use in URLs. Only for use in course activity modules.
- {courseidnumber} : Displays a course's ID number.
- {sectionid} or %7Bsectionid%7D : Displays the section ID (not to be confused with the section number).
- {sectionname} : Displays the section name in which the activity is located.
- {coursemoduleid} or %7Bcoursemoduleid%7D : Course module ID. Only works inside a course activity or resource module.
- {coursecontacts} : (ALPHA) List of the course teachers with optional links to their profile, email address or Moodle messaging.
- {mygroups} : Displays a list of groups to which you are a member.
- {courseunenrolurl} : The course unenrolment URL for you to place in a button or a link anywhere in the course.
- {coursecount students} : Displays the number of students enrolled in the course.
- {coursecount students:active} : Displays the number of users with the role of 'student' in a course who are not suspended in the course.
- {coursegradepercent} : Displays the current accumulated course grade of the student (no percentage symbol).
- {coursegrade} : Displays the student's current overall course grade (with percentage symbol).
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, is otherwise blank.
- {categorynumber} : If in a course, the number of the course's parent category, is otherwise blank.
- {categorydescription} : If in a course, the number of the description of a course's parent category, is otherwise blank.
- {categories} : Displays an unordered list of links to all course categories.
- {categories0} : Displays an unordered list of just top-level links to all course categories.
- {categoriesx} : Displays an unordered list of other categories in the current category.
Custom menu
Note: Filtering must be supported in a custom menu by your theme. See README.md for more information.
- {categoriesmenu} : A second-level list of categories with links for use in custom menus.
- {categories0menu} : A second-level list of just top-level categories with links for use in custom menus.
- {categoriesxmenu} : A second-level list of other categories in the current category with links for use in custom menus.
- {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).
- {courserequestmenu0} : Request a course / Course request in a top-level custom menu.
- {courserequestmenu} : Request a course / Course request in a submenu.
- {menudev} : Useful menu for Moodle developers.
- {menuadmin} : Userful dynamic menu for Moodle administrators, managers and teachers (is context sensitive).
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} or {referrer} : Referring URL
- {protocol} : http or https
- {ipaddress} : User's IP Address.
- {sesskey} or %7Bsesskey%7D : Moodle session key.
- {wwwcontactform} : Action URL for Contact Form forms. (requires Contact Form plugin).
Content
- {global_...} : Use your own custom FilterCodes tags in the filter's settings. This is sometimes referred to as global blocks. An example of this might be if you wanted to define a standardized copyright or other text, email address, website URL, phone number, name, link, support information and more. Define and centrally manage up to 20 global block tags.
- {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.
- {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. - {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/fa-solid/fab/fa-brands fa-...} : Insert FontAwesome icon. Note: FontAwesome Font/CSS must be loaded as part of your theme. For FontAwesome v6.0 icons, you need Moodle 4.2+.
- {glyphicon glyphicon-...} : Insert Glyphicons icon. Note: Glyphicons Font/CSS must be loaded as part of your theme.
- {mycourses} : Displays an unordered list of links to all my enrolled courses.
- {myccourses} : Displays an unordered list of links to all my completed courses - only includes courses with completion tracking enabled.
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. The form includes Subject and Message fields. Note: The 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). The 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. The form includes Name, Email address, Course name, and Course Description.
- {formsupport} : Adds a "Support Request" form to your site (example: in a page). The form includes Name, Email address, pre-determined Subject, specific Subject, URL and Message fields.
- {formcheckin} : Adds an "I'm here!" button to your course. The form does not include any other fields. Note: The 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} : Displays the ReCAPTCHA field - for use with Contact Form for Moodle. Note: Will be blank if a 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 short names. 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} : Displays the enclosed content only if the user is logged in as a non-guest.
- {ifloggedout}{/ifloggedout} : Displays the enclosed content only if the user is logged out or is logged in as a guest.
- {ifloggedinas}{/ifloggedinas} : Displays the enclosed content only if you are logged-in-as (loginas) a different user.
- {ifnotloggedinas}{/ifnotloggedinas} : Displays the enclosed content only if you are logged in as yourself and not a different user.
Courses
- {ifenrolled}{/ifenrolled} : Displays the enclosed content only if the user is enrolled as a student in the current course. This tag does not take any other roles into consideration.
- {ifnotenrolled}{/ifnotenrolled} : Displays the enclosed content only if the user is not enrolled as a student in the current course. This tag does not take any other roles into consideration.
- {ifincourse}{/ifincourse} : Displays the enclosed content only if the user is in a course other than the Front page.
- {ifnotincourse}{/ifnotincourse} : Displays the enclosed content only if the user is not in a course.
- {ifinsection}{/ifinsection} : Displays the enclosed content only if the user is in a section of a course which is not the Front Page.
- {ifnotinsection}{/ifnotinsection} : Displays the enclosed content only if the user is not in a section of a course.
- {ifingroup id|idnumber}{/ifingroup} : Displays content if the user is part of the specified course group ID or group ID number.
-
{ifnotingroup id}{/ifnotingroup} : Displays content if the user is NOT part of the specified course group ID or group ID number.
- {ifprofile_field_shortname}{/ifprofile_field_shortname} : Displays the enclosed content if the custom profile field is not blank/zero.
- {ifactivitycompleted id}{/ifactivitycompleted} : Displays content if the activity or resource specified by ID has been completed.
- {ifnotactivitycompleted id}{/ifnotactivitycompleted} : Displays content if the activity or resource specified by ID has not been completed.
- {ifinactivity}{/ifinactivity} : Displays enclosed content if the user is currently inside an activity or resource.
- {ifnotinactivity}{/ifnotinactivity} : Displays enclosed content if the user is not currently inside an activity or resource.
- {ifvisible}{/ifvisible} : Displays the enclosed content if the course visibility is set to Show.
- {ifnotvisible}{/ifnotvisible} : Displays the enclosed content if the course visibility is set to Hide.
Roles
- {ifguest}{/ifguest} : Displays the enclosed content only if the user is logged in as a guest.
- {ifstudent}{/ifstudent} : Displays the enclosed content only if the user is logged in and enrolled in the course (no other roles).
- {ifassistant}{/ifassistant} : Displays the enclosed content only if the user is logged in as a non-editing teacher in the current course.
- {ifminassistant}{/ifminassistant} : Displays the enclosed content only if the user is logged in as a non-editing teacher or above in the current course.
- {ifteacher}{/ifteacher} : Displays the enclosed content only if the user is logged in as a teacher in the current course.
- {ifminteacher}{/ifminteacher} : Displays the enclosed content only if the user is logged in as a teacher or above in the current course.
- {ifcreator}{/ifcreator} : Displays the enclosed content only if the user is logged in as a course creator.
- {ifmincreator}{/ifmincreator} : Displays the enclosed content only if the user is logged in as a course creator or above.
- {ifmanager}{/ifmanager} : Displays the enclosed content only if the user is logged in as a manager.
- {ifminmanager}{/ifminmanager} : Displays the enclosed content only if the user is logged in as a manager or above.
- {ifminsitemanager}{/ifminsitemanager} : Displays the enclosed content only if the user is logged in as a site manager or above.
- {ifadmin}{/ifadmin} : Displays the enclosed content only if the user is logged in as an administrator.
- {ifcustomrole roleshortname}{/ifcustomrole} : Displays enclosed content only if the user has the custom role specified by its short name within the current context.
- {ifnotcustomrole roleshortname}{/ifnotcustomrole} : Displays enclosed content only if the user does not have the custom role specified by its short name within the current context.
- {ifincohort CohortID|idnumber}{/ifincohort} : Displays enclosed content only if the 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, dash and underscores. It will not work if it contains spaces or other special characters.
- {ifhasarolename roleshortname}{/ifhasarolename}: Displays enclosed content if the user has been assigned the specified role anywhere in the Moodle site within any context.
Miscellanious
- {ifdev}{/ifdev} : Displays the enclosed content only if the user is logged in as an administrator and developer debugging mode is enabled.
- {ifhome}{/ifhome} : Displays the enclosed content only if the user is on the Moodle Home Frontpage.
- {ifnothome}{/ifnothome} : Displays the enclosed content only if the user is not on the Moodle Home Frontpage.
- {ifdashboard}{/ifdashboard} : Displays the enclosed content only if the user is on the Moodle Dashboard.
- {ifcourserequests}{/ifcourserequests} : Displays enclosed contents only if the Request a Course feature is enabled.
- {ifeditmode}{/ifeditmode} : Displays the enclosed content only if editing mode is turned on.
- {ifmobile}{/ifmobile} : Displays the enclosed content if it is being accessed from the mobile app or through a Web service.
- {ifnotmobile}{/ifnotmobile} : Displays the enclosed content if not being accessed from the mobile app or through a Web service.
If the condition is not met in the particular context, the specified tag and its content will be removed.
Conditionally display content filters (For Moodle Workplace)
- {iftenant idnumber|tenantid}{/iftenant} : Displays the content if a tenant id number or tenant id is specified. Only {iftenant 1} will work in Moodle classic.
- {ifworkplace}{/ifworkplace} : Displays 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 use this localization information to apply a particular pronunciation if the text is in a different language than the rest of the page. This is required for compliance with W3C Web Content Accessibility Guidelines (WCAG 2.0)
- {multilang}{/multilang} : A plain-text substitute for Moodle core's Multi-Language Content filter span tags. For this tag to work, the Multi-Language Content filter must be enabled as FilterCodes doesn't do any language filtering itself. It just makes it easier to tag the text.
- {details}{summary}{/summary}{/details} : An easy way to create an HTML 5 Details/Summary expandable section on 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 experimental feature may result in invalid HTML, but it works.
- {hr}: Displays a horizontal rule line.
For more information and an up-to-date list of tags, see the README.md documentation file included with the plugin.
I have a question.
en {label backgroundtype}{/label} : Display text over a color background. how can i put the color
since {coursecontacts} is not possible to change the color
Thank you: Gerardo Diaz
This is a really wonderful and helpful plugin. I am looking for someway to show the activity/resource name, but could not find it in the list above or on github. Is there anyway to use it or add it?
Thanks a lot.
BUT:
in addition to "all courses" (with {coursecards}) or "all courses from an cat. ID"( with {coursecards 2})
will there also be a way to add just a SINGLE course by it's ID?
then I can create a list of random courses from different categories bij adding them (manually).. IE:
{coursecardid 2} - {coursecardid 12} - {coursecardid 5} - {coursecardid 24}
is that something that would be possible (in the near future?)
THIS IS ABSOLUTELY AWESOME! The functionality/customization this adds is simply mindblowing!
I was wondering if it were possible to use filtercodes to display user pictures based on a variable.
We have a custom user field "Organization" and would like for the user picture to be based on what organization they are in.
ex: Steve is in X, so his user picture is X's logo. Jane is in Y, so her user picture is Y's logo.
Can something like this be done through FilterCodes?
Best regards,
Michael
Unfortunately FilterCodes can only substitute text tags for content. The user picture is not a text field so you cannot add a filter code tag to it.
That said, what you are trying to do is possible however, it requires making a change to the code of your theme. I recommend that you contact a developer, like me, to see if they can customize your theme for your needs.
Best regards,
Michael
Thanks for this amazing plugin! The Show {categorycards} background option states that if enabled, will display a background colour/pattern for {categorycards} tag similar to the course images when no image was specified. I have several categories that have images however all that is displayed when I insert the tag is the category cards with the names and a pattern - no category image. What am I missing?
Check the FilterCodes settings. There is a setting for that.
Best regards,
Michael Milette
Thanks for the quick response. I have enabled the Show {categorycards} background option in the FilterCodes settings but still I only see patterns as the background behind my category cards not the images that are part of the category description. Is there another setting I need to enable?
Thanks,
Joe
Michael
Thanks for the update and the alternate solution.
Keep up the great work!
Joe