Filters: Generico Filter
Generico is a simple templating filter, that allows you to set up text and code snippet templates for use in Moodle text areas. It will allow an unlimited number of templates to be registered. When Moodle encounters a Generico filter string it will use the data in the filter string to fill out the template, and insert it into the page. See it in action on the Generico course on the PoodLL demo site.
It is useful for ad-hoc template purposes where writing a new plugin would be overkill, or just for re-using common pieces of text. It can be used to centralise and manage the embedding of iframe content from video hosting services, and educational app providers.
In the latest version there are approx. 20 presets from which you can make templates. They include info box, tabset, accordian, lightbox, screenr and image gallery. And there is a companion Atto editor plugin for Generico. The combination of these two features make it possible to use Generico like the Wordpress shortcode plugins.
This 8 minute video walks through the basic Generico Filter and should give you a good idea of what it is, and how it works.
You can define templates for use with the filter at:
Site Administration -> plugins -> filters -> Generico
A template consists of a "key", a "template," and some "defaults."
The key is just a one word name, that tells Generico which template to use.
The template is just passage of text that you want to use, and the parts of the template that you want to mark as variables you surround in @@ marks.
The defaults are a comma delimited list of variablename=value pairs. It is possible to specify multiple values for a single variable in the defaults. The Generico Atto editor plugin will display these values in a drop down list. eg size="100|120|140". The first of the values will be the true "default."
Here is an example template.
template: Inside this box are @@thing1@@ and @@thing2@@
template defaults: thing2=Silly
A possible filter string for this "wildthings" template would look like this:
Generico would replace the above filter string with:
"Inside this box are Sally and Silly"
The filter string must follow this format,
The wildthings example above is trivial of course. Imagine using it to embed YouTube videos by registering the standard iframe code YouTube gives you, as a template. Then it would only be necessary to insert the id of the video in a generico filter string.
So that people can share the templates they have made, there is a system to share them called "bundles." On each template settings page there is a green bundle box.
If you click on the box, it will automatically download the "bundle" as a text file. If you then drag that bundle (or somebody else's bundle) onto the green bundle box of another template, it will fill up the template. Be sure to save the template after you have done that though.
There are a number of bundles that people have shared over in the this forum thread. https://moodle.org/mod/forum/discuss.php?d=324771
USER PROFILE VARIABLES
It is also possible now to add user profile variables to your templates. Just make the first part of the variable name USER: and the next part the name of the user profile field. It also works with custom profile fields. There are two "special" user profile fields, picurl and pic that respectively output the url of the user's profile pic, and their picture itself.
e.gUser's first name: @@USER:firstname@@
User's ice cream preference (custom profile field): @@USER:icecreampref@@
Users profile pic url: @@USER:picurl@@
User's profile pic: @@USER:pic@@
If you are uploading Generico, first expand the zip file and upload the generico folder into:
[PATH TO MOODLE]/filters.
Then visit your Moodle server's notifications page.
Site Administration -> Notifications
Moodle will guide you through the installation. On the final page of the installation you will be able to register templates. You can choose to skip that and do it later from the Generico settings page if you wish.
After installing you will need to enable the Generico filter. You can enable the Generico filter when you visit:
Site Administration -> plugins -> filters -> manage filters