Generico Filter

Filters ::: filter_generico
Maintained by Justin Hunt
Generico is a simple filter for creating templates of code snippets and text that can be inserted into Moodle text areas.
Latest release:
2421 sites
689 downloads
99 fans
Moodle 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 4.0, 4.1, 4.2, 4.3, 4.4

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. 

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
Screenshot #2
Screenshot #3

Contributors

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

Comments RSS

Show comments
  • Justin Hunt
    Wed, 18 Sep 2024, 3:31 PM
    There are many cool things still to be built.That would be one of them. In the meantime you can use my Zapier integration to integrate with Mailchimp. See here: https://support.poodll.com/en/support/solutions/articles/19000161459-connecting-moodle-to-mailchimp
  • Laurent Dairaine
    Sat, 19 Oct 2024, 9:15 PM
    Hi Justin. I have installed the "Custom field for Activity Module" https://moodle.org/plugins/local_modcustomfields that allow to define fields using standard Moodle approach. Then How to access these fields from GENERICO?
  • Justin Hunt
    Sat, 19 Oct 2024, 9:48 PM
    HI Laurent. I don't know, I have never tried. I suspect Generico needs to add support for the custom fields api for that to be possible. If it helps, you can use Course custom fields in Generico. Also, I don't think you should post your question here and in the local_modcustomfields plugin. Both devs have to answer.
  • Mary Blue
    Wed, 20 Nov 2024, 6:29 PM
    Dear Justin, I really love your plugin. Especially because it gives us the possibility to manage standard content like texts that you find in any couse from a central position in the system. Just great!!!
    My question for is, if it is possible to display the progressbar for activities in a course through the generico filter.
  • Dave Foord
    Tue, 11 Mar 2025, 10:15 PM
    I am trying to write some how to guides for staff inside Moodle, and I want the generic filter to display as text, but not render as the filter. I need to keep the filters active on the page for other things. are them some 'tags' I can put around the filters to stop them rendering?
  • Justin Hunt
    Wed, 12 Mar 2025, 9:08 AM
    Hi Dave, thats a super question because there is indeed a way to do that. The very last attribute on the filterstring, with no spaces or quotes should be; passthrough=1
    e.g {GENERICO:type="houses",color="green",owner="jim",passthrough=1}

    Also note that there is some old but still applicable documentation here: https://poodll.freshdesk.com/a/solutions/articles/19000083258
  • Dave Foord
    Wed, 12 Mar 2025, 3:05 PM
    Thanks Justin - that works. I am loving this plugin.
  • Dave Foord
    Thu, 3 Jul 2025, 9:27 PM
    Hi Justin - as you may have worked out by now, I love this plugin and what it can do, and have been doing some really cool stuff by combining this with https://moodle.org/plugins/filter_filtercodes - e.g. having filter codes inside the Generico filter.

    However, this particular method is not working on one of my newer sites - I have spent ages checking that the syntax is correct and the filter order is set correctly. The only difference that I can see is my newer site has Generico version 1.4.22 and my other sites are on Generico 1.4.21 or earlier. Looking at the change log for version 1.4.22 it says 'Better cleaning up of filter string inputs to prevent variable injection and meddling' - will this have stopped the filter codes from working inside a Generico filter?

    Is there a way that I can get my filter codes working again?

    Thanks in advance
  • Justin Hunt
    Fri, 4 Jul 2025, 12:19 PM
    Hi Dave, It does sound like you are a casualty of that 1.4.22 update but its hard to know really. That update prevented people putting odd parameters into the filter string. e.g to overwrite "system variables" like WWWROOT. It doesn't really change what happens after that.

    Parsing other filters inside of Generico should still work. I dont think anything changed apart from the parameters that go into the filter string.
  • Dave Foord
    Mon, 7 Jul 2025, 11:46 PM
    @Justin - following on from my previous message, the upgrade to 1.4.22 doesn't appear to be the issue, as I have found another site with same versions where this works, and if I add a new course to the site I was having problems with, then it works in the new course. So there is something cranky in the original course that is interfering - I haven't worked out what yet, but if I do I will report back here in case it helps anyone else.
  • Dave Foord
    Thu, 10 Jul 2025, 11:47 PM
    Just in case anyone else has the same problem that I had with the filter codes filter not working inside the Generico filters, I have made some progress: If I have a course where this is a problem, if I turn the Generico filter off within the course, then view the course, then go back and turn the Generico filter back on, it then appears to work as expected. Obvioulsy not sure what the root cause is here, but the old technical approach of 'turn it off, and turn it on again' seems to solve it!
  • Justin Hunt
    Fri, 11 Jul 2025, 8:33 AM
    Hi Dave, interesting. If that solves the problem then I think the root cause is possibly the order of the filter processing. When you disable and re-enable, the re-enabled filter is usually last in the processing. However at course level that should not change (Order of filters is not an option in the filter settings at course level). Anyway I am glad its working.
  • Mary Blue
    Fri, 11 Jul 2025, 3:12 PM
    Hello Justin, when will it be possible to use the course image as a variable in the Generico filter?
  • Dave Foord
    Fri, 11 Jul 2025, 4:12 PM
    Mary - if this cannot be done directly with Genrico filter alone, this is a great example of where the filter codes filter can work brilliantly with Generico, you just need to ensure that Genetico filter appears above filter codes in the order of filters.
  • Mary Blue
    Fri, 11 Jul 2025, 4:24 PM
    Dear Dave, thanks for the quick response. But I am not sure, I really get it.
    I want to put the "front page" of a course, that appears in 1.000 courses in the template of a Generico Filter - including the variable for the course image.
    So that only the template key is in the text field in the course.
    If we change anything about the text or position of the image or anything else in the structure of front page in the next years, we only have to do it in the filter template and not in all the courses.
    As far as I know, the filter code {courseimage} (or @@COURSE:image@@) does not work in the Generico template.
    Do you have a solution for that?
1 2 3 4 5 6 7 8
Please login to post comments