FilterCodes

Filters ::: filter_filtercodes
Maintained by Michael Milette
The FilterCodes filter enables Moodle content creators to easily customize and personalize site and course content using over 140 plain text tags. Version 2.2 introduces 12 new FilterCodes including tags to list teacher, course request link, a conditional tag based on custom profile fields, tags to display support information, a menu of tools for developer and more. You can now even create your own global tags.
Latest release:
2295 sites
863 downloads
120 fans
Current versions available: 1

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.
  • Insert support information in every course and manage that information centrally.
  • Easily list teachers in your course.

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.
  • {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.
  • {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.

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.
  • {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} : 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}: Display a course's context ID.
  • %7Bcoursecontextid%7D : Display a course's context ID - for use in URLs. Only for use in course activity modules.
  • {courseidnumber} : Display a course's ID number.
  • {sectionid} : Display the section ID (not to be confused with the section number).
  • {courseteachers} : (ALPHA) List of course teachers with optional link to their profile, email address or Moodle messaging.

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

Note: Filtering must be supported in 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 submenu.
  • {menudev} : Useful menu for Moodle developers.

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

  • {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/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 as a student in the current course. This tag does not take any other roles into consideration.
  • {ifnotenrolled}{/ifnotenrolled} : Will display 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} : 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.
  • {ifprofile_field_shortname}{/ifprofile_field_shortname} : Will display the enclosed content if the custom profile field is not blank/zero.

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.

Screenshots

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

Contributors

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

Comments RSS

Comments

  • Fri, Jul 14, 2017, 1:30 PM
    Approval issue created: CONTRIB-6980
  • Thu, Oct 5, 2017, 12:53 AM
    I really like this plugin! If you could add "Alternate name" to the list, that would be awesome! We have so many students (especially international) who do not use their legal names in class.
  • Thu, Oct 5, 2017, 12:55 AM
    Although... now that I think of it, I'm not sure how I would set that up to use the alternate name if one exits and NOT use the firstname in those situations. "Hello, {firstname}{altname}" would show one name if the student hasn't filled in the alternate name, but two names if they have. Hmmm..
  • Fri, Oct 6, 2017, 3:16 PM
    Conflicts with plugin "Simple Certificate": they use {username} for printing first and last name on certificates. Using FilterCodes prints the username on the certificates. Raised a tracker at the Simple Certificate Plugin to change that. Meanwhile: be aware.
  • Fri, Oct 6, 2017, 3:28 PM
    In order to avoid misunderstanding: FilterCodes is marvellous. Let's get it into quickmail and messaging too!
  • Wed, Oct 18, 2017, 6:39 AM
    Hi Bert, thanks! Glad you like it. It is unfortunate that there is a conflict with Simple Certificate, another great plugin I've used myself on several Moodle sites. Do take a look at the bug tracker where I have proposed a solution. As for getting it into Quickmail and messaging too, it's a Moodle filter. If the plugins make use of format_text() and format_string() functions, FilterCodes will work. It's up to the author of the plugins to apply the functions.
  • Wed, Oct 18, 2017, 6:41 AM
    Hi Blair, thanks for the suggestion. I have great news for you. The next release of FilterCodes will include a new tag called {alternatename}. And just for you, if it is empty, it will be substituted with the user's firstname. That way you don't need to deal with firstname or alternatename. It will just always work with {alternatename}. smile
  • Mon, Nov 13, 2017, 4:46 PM
    Thanks great tool. Can you check the lang file. There are four empty strings.
  • Mon, Nov 13, 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
  • 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
  • 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.
  • Thu, Nov 16, 2017, 5:43 AM
    Hey, thanks, Michael! I just read your reply from October 17th!
  • 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!
Please login to post comments