Filters: Generico Filter

filter_generico
Maintained by Picture of Justin HuntJustin Hunt
Generico is a simple filter for creating templates of code snippets and text that can be inserted into Moodle text areas.
1336 sites
1k downloads
49 fans
Current versions available: 2

Generico is a simple templating filter, that allows you to set up text and code snippet templates for use in Moodle text areas. It allows 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 templates for an info box, tabset, accordian, lightbox 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. 



How it works

Templates for use with the filter are available at:

Site Administration -> plugins -> filters -> Generico -> templates

A template primarily consists of a "key", a "template," and some "defaults." (It can also load CSS and Javascript. But for now lets keep things simple.)

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.

templatekey: wildthings

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:type=wildthings,thing1=Sally}


Generico would replace the above filter string with:

"Inside this box are Sally and Silly"


The filter string must follow this format,

{GENERICO:type=templatekey,variable1=data1,variable2=data2}


The wildthings example above is trivial of course. Instead 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 and the template would do the rest. e.g

{GENERICO:type=youtube,id=ABC12345678}


USING PRESETS

Generico comes with about 20 template presets. By default they are not set up as templates yet. To create the actual template:

  1. Open an empty template settings page
  2. Select a preset from the dropdown list at the top of the page
    This will fill in the fields on the template settings page.
  3. Press the "Save Changes" button at the bottom of the page.


USING BUNDLES

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 the fields on that template settings page. Be sure to save the template after you have done that.

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


And there is a special category here on the Moodle plugins directory for sharing templates: 
https://moodle.org/plugins/browse.php?list=category&id=69



USER PROFILE VARIABLES

It is also possible 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.g

User'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@@


INSTALLATION

Generico installs like any Moodle plugin. Please see here for more information on that process:
https://docs.moodle.org/en/Installing_plugins#Installing_directly_from_the_Moodle_plugins_directory

On the final page of the installation you will be able to register templates. its best to skip that step, and just press "save changes." Later you can do this from the Generico template settings pages.


After installing you will need to enable the Generico filter. You can enable the Generico filter at:

Site Administration -> plugins -> filters -> manage filters

More Documentation

https://docs.moodle.org/31/en/filter_generico

https://poodll.freshdesk.com/solution/articles/19000083258-how-do-widgets-work-for-developers-


Screenshots

Screenshot #0
Screenshot #1

Contributors

Picture of Justin Hunt
Justin Hunt (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Comments

  • Picture of Justin Hunt
    Tue, Nov 17, 2015, 4:49 PM
    I figured I might as well just go through and implement this. So I did that. Both the Generico filter and the Atto Generico plugins have been updated on github. I won't put them on Moodle.org till I am pretty sure they work ok. But they work ok. In the Generico common filter settings there is now a setting for the number of templates, the default is 20. If you up that, you will need to click on the site admin -> notifications link for the new template settings to be picked up. ( i was surprised that worked). Please try it out and report back.

    Generico Filter Github: https://github.com/justinhunt/moodle-filter_generico
    Atto Github : https://github.com/justinhunt/moodle-atto_generico
  • Picture of Justin Hunt
    Tue, Nov 17, 2015, 4:49 PM
    I figured I might as well just go through and implement this. So I did that. Both the Generico filter and the Atto Generico plugins have been updated on github. I won't put them on Moodle.org till I am pretty sure they work ok. But they work ok. In the Generico common filter settings there is now a setting for the number of templates, the default is 20. If you up that, you will need to click on the site admin -> notifications link for the new template settings to be picked up. ( i was surprised that worked). Please try it out and report back.

    Generico Filter Github: https://github.com/justinhunt/moodle-filter_generico
    Atto Github : https://github.com/justinhunt/moodle-atto_generico
  • Picture of dan k
    Thu, Nov 19, 2015, 6:43 AM
    Awesome Justin! That works perfectly fine!!!! Thank you!!!!
  • Picture of Jarreau Mathys
    Thu, Dec 3, 2015, 8:19 PM
    Is there a way to pass a variable from an android system into moodle such as a device id? Or to look up something from outside of moodle? Thanks

  • Picture of Justin Hunt
    Thu, Dec 3, 2015, 9:38 PM
    That starts to stretch it a bit really. There are some preset variables that contain information passed in from PHP. If you were making a custom solution, you could just add to those by modifying filter.php (and friends). But if you wanted to do it via javascript, without modifying Generico, the information that you use in the template would need to be available from javascript. If it is, then you should be able to use it.
  • Pimenko
    Thu, Dec 17, 2015, 12:10 AM
    Hi,

    Thank you for your plugin. I use your plug-in to embed responsive video in my theme. Very usefull for me. Peoples can add video without use html code.
    I share my method, perhaps it can help someone.

    I use this setting with Generico Template template with this :

    1. The key that identifies template
    Youtube

    2. The body of template

    Bis : you can use Vimeo, it's works fine too.


    In my theme CSS, I add this :

    .videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 0px;
    height: 0;
    }
    .videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    }

    Best regards
  • Pimenko
    Thu, Dec 17, 2015, 12:11 AM
    Me again, point 2. The body of template is missing. Here it is :


    2. The body of template


    ++
  • Picture of ALEXANDER ARCANA MENDOZA
    Thu, Mar 3, 2016, 9:55 AM
    Hi Justin, I would like to know how to use it in Moodle 2.5, and install and can achieve access templates, which can not be accessed from the text editor, how could I use it?
  • Picture of Raimen R
    Wed, May 4, 2016, 3:17 PM
    Hi Justin,

    great work! We use Moodle v2.8 & I've downloaded the plugin from moodle.org instead of github after reading your github note.

    Just double-checking, if I've more than 20 templates should it work for the version I downloaded? Your comment indicates (https://moodle.org/user/view.php?id=14534&course=1) the version hosted here wouldn't work.

    We'll basically use the plugin for re-using text blocks for different courses. So it's important to have the capability of unlimited template (i.e. out-of-the-box if possible).

    Could you please confirm? Thanks Justin.

  • Picture of Phuong Hoang
    Fri, Jul 29, 2016, 9:05 PM
    Thank you so much. A very useful plugin. It's worth spending time playing around.
  • Picture of Jeff White
    Fri, Nov 11, 2016, 10:31 PM
    One of the best plugins ever made. Is there like a repository for us to share things we have done using this plugin? I wouldn't mind sharing some of the filters I have managed to get working smile. Maybe someone else might find them useful with their work.
  • Picture of Justin Hunt
    Mon, Nov 14, 2016, 2:00 PM
    Hi Jeff

    Thanks for the vote!! Right now people just post them in this forum: https://moodle.org/mod/forum/discuss.php?d=324771

    I have made a few a half hearted attempts at a gallery of sorts for the plugins but was generally beaten back by life(or in one case a server crash). More recently I set up a Moodle Database activity on the PoodLL demo site, and got as far as one template uploaded and explained. https://demo.poodll.com/mod/dataform/view.php?id=196

    But it is not actually the right place for this. Because it gets reset each day, so I am the only one who can really edit it permanently.
    [ .... thinking ...]
    How about we set up a special site for sharing templates on MoodleCloud? Does that sound like a good idea? (Generico itself is not installed there, but thats ok ... isn't it?)

    Its a real shame, there are some really good templates out there. Hmmmmm Perhaps we could make a generico site on Moodle cloud for this purpose? The plugin itself is not installed there, but we could use the Moodle database
  • Picture of Данияр Нугуманов
    Thu, Dec 15, 2016, 6:01 PM
    Hello. help me plz

    i dont know why page /admin/settings.php?section=filter_generico_templatepage_1 is not fully loaded

    It's happends when i am trying to edit template

    how to fix it

    Moodle 2.7.14 (Build: 20160509)
  • Picture of Justin Hunt
    Fri, Dec 16, 2016, 7:00 AM
    2.7 is quite old now. What version of the Generico filter are you using? If it's a recent version it will be using AMD which didn't come along until 2.9. The supported versions of Moodle are listed with each of the versions of Generico on the Moodle plugins page
  • Picture of Данияр Нугуманов
    Tue, Dec 20, 2016, 1:00 PM
    Justin Hunt, thank you!
Please login to post comments