FilterCodes使用方法

本文出自官方明细教程

Usage

IMPORTANT: This STABLE release has been tested on many Moodle sites. Although we expect everything to work, if you find a problem, please help by reporting it in the Bug Tracker.

{FilterCodes} are meant to be entered as regular text in the Moodle WYSIWYG editor through they will work equally well if entered in the code view.

Moodle metadata filters

  • {firstname} : 显示用户姓名
  • {surname} or {lastname} : 显示用户班别
  • {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} : 显示用户名
  • {scrape url="..." tag="..." class="..." id="..." code="..."} : Scrapes the content from another web page. Must be enabled in FilterCodes settings.
  • {userpictureurl X} : 用户照片URL X 代表大小,可以是 sm (small), md (medium) or lg(large). 
  • {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.
  • {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} : 显示课程全程或者站点全称
  • {courseshortname} : 显示课程简称或者站点简称
  • {coursestartdate} : 显示课程开始日期. Will display "Open event" if there is no start date.
  • {courseenddate} : 显示课程结束日期. 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).
  • {mycourses} : Display an unordered list of links to all my enrolled courses.
  • {mycoursesmenu} : A second level list of courses with links for use in custom menus (filtering must be supported by the theme).
  • {categories} : Display an unordered list of links to all course categores.
  • {categoriesmenu} : A second level list of categories with links for use in custom menus (filtering must be supported by the theme).
  • {institution} : Display the name of the institution from the user's profile.
  • {department} : Display the name of the department from the user's profile.
  • {courseid} or %7Bcourseid%7D : Display a course's ID.
  • {sectionid} : Display the section ID (not to be confused with the section number).
  • {wwwroot} : Display the root URL of the Moodle site.
  • {pagepath} : Path of the current page without wwwroot.
  • {protocol} : http or https
  • {referer} : Referring URL
  • {referrer} : Alias of {referer}
  • {ipaddress} : User's IP Address.
  • {sesskey} or %7Bsesskey%7D : Moodle session key.
  • {recaptcha} : Display the ReCAPTCHA field - for use with Contact Form for Moodle. Note: Will be blank if user is logged-in using a non-guest account.
  • {readonly} : To be used within form input fields to make them read-only if the user is logged-in.
  • {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".
  • {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.

Conditionally display content filters

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.

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

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

HTML and "lang" tagging

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

The opening {langx xx} tag should also include two ISO 639-1 language code abbreviation letters in lowercase associated with language's name. French, for example, has the code fr:

{langx fr}Contenu{/langx}

The {langx fr}{/langx} filter will convert this into the following HTML

<span lang="fr">Contenu</span>

FilterCodes in a custom menu

Here are a couple of examples of how to create really useful custom menus using FilterCodes. Just copy and paste the code into the Custom menu items field (Site administration > Appearance > Theme settings)

Feel free to customize these for your own needs and to make more of these for other roles like Course creators, Teachers, Teacher assistants and even Students.

Doesn't work? If FilterCodes doesn't work with your theme, contact the developer / maintainer of the theme and refer them to the FAQ section of this documentation to provide them with an easy way for them to enable support for Moodle filters.

General menu

This will add a Home link, a listing of categories, a listing of courses in which you are currently enrolled, and a Logout link, but only if you are currently logged in.

Home|\
Course catalogue
{categoriesmenu}
{ifloggedin}
My Courses
{mycoursesmenu}
Logout|/login/logout.php?sesskey={sesskey}
{/ifloggedin}

Admin menu

This menu can be handy for Moodle administrators and managers.

{ifminmanager}
Admin
{ifadmin}
-Moodle Settings
--Additional HTML|/admin/settings.php?section=additionalhtml
--Advanced features|/admin/settings.php?section=optionalsubsystems
--Frontpage|/admin/settings.php?section=frontpagesettings
--Notifications|/admin/index.php
--Plugin overview|/admin/plugins.php
--Profile fields|/user/profile/index.php
--Support contact|/admin/settings.php?section=supportcontact
--Theme settings|/admin/settings.php?section=themesettings
-Install
--Plugin|https://moodle.org/plugins
--Theme|https://moodle.org/plugins/browse.php?list=category&id=3
{/ifadmin}
-This course
--Turn editing on|/course/view.php?id={courseid}&sesskey={sesskey}&edit=on
--Course Backup|/backup/backup.php?id={courseid}
--Enrolled users|/enrol/users.php?id={courseid}
--Manage badges|/badges/index.php?type={courseid}
--Reset course|/course/reset.php?id={courseid}
-Add new course|/course/edit.php?category=1&returnto=topcat
-Course management|/course/management.php
-Restore Course|/backup/restorefile.php?contextid=1
-System reports|/admin/category.php?category=reports
-User management|/admin/user.php
-###
-Moodle support|https://moodle.org/course/view.php?id=5
{/ifminmanager}

In this extensive example, part of the custom menu will appear only to users with a manager role while everything will appear to administrators. Nothing will appear for everyone else.

Developer menu

If you are a developer, this little menu is worth installing FilterCodes alone.

Together with the Administration menu above, these can be a real productivity boost for developers who are tired of always digging through the Site administration block to find the options they are looking for. Tailor it to your particular projects with links to any page you need regularly:

{ifadmin}
Dev tools
-Configure debugging|/admin/settings.php?section=debugging
-Code checker|/local/codechecker
-Moodle PHPdoc check|/local/moodlecheck
-Purge cache|/admin/purgecaches.php?confirm=1&sesskey={sesskey}
-###
-Adminer|/local/local/adminer
-PHP Info|/admin/phpinfo.php
-###
-Developer docs|https://moodle.org/development
-Developer forum|https://moodle.org/mod/forum/view.php?id=55
-Tracker|https://tracker.moodle.org/
-AMOS|https://lang.moodle.org/
{/ifadmin}

Tip: Are you a theme developers? Add a direct link to your theme's settings page.

Notes:

Scrape'ing content

Note: This feature must be enabled in FilterCodes settings.

As of version 0.4.7, you can now use FileterCodes to scrape content from another web page. Your mileage may vary and depends a lot on your configuration, the website from which you are scraping content and more.

{scrape url="..." tag="..." class="..." id="..." code="..."}

Tip: When adding this tag in one of Moodle's WYSIWYG editors like Atto or TinyMCE, the tag may end up embedded in a set of HTML paragraph tags. If this happens, the content you are scraping may not result in valid HTML. To fix the problem, you will need to go into the source code view of the editor and replace the P (paragraph) tags with div and then save. Alternatively, if there is nothing else in the editor, you can remove everything before and after the tag and save.

Parameters:

  • url = The URL of the webpage from which you want to grab its content.
  • tag = The HTML tag you want to capture.
  • class = Optional. Default is blank (class is irrelevant). Class attribute of the HTML tag you want to capture. Must be an exact match for everything between the quotation marks.
  • id = Optional. Default is blank (id is irrelevant). id tag of the HTML tag you want to capture.
  • code = Optional. Default is blank (no code). This is URL encoded code that you want to insert after the content. Will be decoded before being inserted into the page. Can be things like JavaScript for example. Be careful with this one. If not encoded, will result in error.

If the URL fails to produce any content (broken link for example), a message will be displayed on the page encouraging the visitor to contact the webmaster. This message can be customized through the Moodle Language editor.

If a matching tag, class and/or id can't be found, will return all of the page content without being filtered.

Back to section / Back to course

Help students navigate your Moodle site by implementing this handy-dandy BACK button. Works at both the section and activity level.

<p style="float:right;"><a href="{wwwroot}/course/view.php?id={courseid}&amp;section={sectionid}" class="btn btn-outline" style="font-size:14px;">Go Back</a></p>

If you are in a section and want to go directly back to the main course outline but scroll down to the current section, try this:

<p style="float:right;"><a href="{wwwroot}/course/view.php?id={courseid}#section-{sectionid}" class="btn btn-outline" style="font-size:14px;">Back to course outline</a></p>

Optional FilterCodes for Moodle settings

FilterCodes for Moodle includes the following settings. These are available on the plugin's Settings page by going to:

Site administration > Plugins > Filters > Filter Codes

Custom navigation support

Experimental: Enable support for FilterCode tags in Moodle custom navigation menu. Note: Is known to be compatible with Clean and Boost based themes.

NOTE: Does not filter tags on the Moodle Theme Settings page. This is not a bug. It is just the way it has to be for now.

Scrape tag support

Enable or disable the {scrape} tag.

(Back to top)


最后修改: 2019年06月12日 星期三 20:43