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:
2359 sites
520 downloads
92 fans
Current versions available: 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
  • Richard Newton
    Fri, 6 Aug 2021, 4:56 PM
    Hi again Justin,

    That's great news!

    Annoyingly the Moodle site I manage is provided to us by a third party and they handle plugin updates and installs (ugh). I've raised a ticket with them to get it updated and I'll keep you in the loop.

    Thanks for the swift response and fix. We're doing some really powerful stuff with this (fantastic) plugin.

    Cheers,

    Richard
  • Richard Newton
    Fri, 6 Aug 2021, 6:09 PM
    Hi again (again),

    All working great this end! Thanks for the super speedy fix!!

    Richard
  • Richard Newton
    Wed, 18 Aug 2021, 5:03 PM
    Hi Justin,

    Everything's been going well! Think I may have spotted another bug?

    When I have decimal number values that end in a 0, the 0 isn't being passed. For example, 21.10 becomes 21.1. A couple of my templates need to return a single row, so if I have a value of 21.1 and 21.10 somewhere in the same column, I'll get an error.

    I'm getting round it by adding a space next to the value in the database, and then adding that space when I use it in the filter (I guess this then turns it into a string as it's being passed?).

    Eitherway, just thought I'd let you know.

    Cheers again,

    Richard
  • Repasemos Ruben
    Fri, 17 Sep 2021, 7:27 PM
    Hi there! First of all, thank you very much for this awesome plugin! I'm building my complete moodle structure using it.

    But, I came across one issue: Is there any possibility to use (Stash) shortcodes in within Generico Templates?
    [stashdrop secret="yECVEk" text="Pick up!" image]
    I've tried -almost- everything, but didn't work, I guess Atto has to render that shortcode, but it's not working inside Generico! Maybe including some js/library inside the template??

    I know I can just put them between tag and _endtag but I will have so many courses that that's really life changing... more if at any time on the future I can change it only with changing the Template! Thank you very much! I really will apreciate it!
  • Justin Hunt
    Sat, 18 Sep 2021, 7:19 AM
    Hi Repasemos, Though I never did it, I think you can just put your stash tags in the body of the Generico template. And move the Generico filter higher (ie earlier) than Stash in the list of filters under site admin -> plugins -> filters-> manage filters. Then Generico filter will put the stash tags on the page, and Stash will process the stash tags shortly after.
  • el la
    Mon, 25 Apr 2022, 5:48 PM
    Hi there smile

    I there !
    I have some isues when I use the Tiles Format with the Generico Filter.
    All of my generico css files are not dowloading on the server.... sad
    It's seems that there's a conflit between the "Tiles format" and the "generico filter", and I have no problem with the css of the other format...
    I have have JS error
    one of you guys had this problem or any ideas of what would be the conflict ??
    Thank you very much! I really'll apreciate it!
  • Justin Hunt
    Thu, 28 Apr 2022, 2:17 PM
    I think this is just a problem when the filter is used to display something on the tile itself, e.g in a label. Is that right?
    There is some problem here I think because of the way elements are loaded into the tile. Basically Generico can't see those elements, and so cant act on them. At least thats my recollection. If you can tell us what template you are using, and what error message you are getting that would help. This is not the best place for support though really. The Generico forum thread in the general plugins forum might be better
  • Marc Couture
    Sat, 15 Oct 2022, 3:09 AM
    Hi Justin, we are required to add French instructions for our users who insert code templates using the Generico Atto icon. Do I need to add translations in each code template, or is there another centralized area where I can do so?

    Thanks again for all of your work on Generico (as well as PoodLL!).
  • Richard Newton
    Wed, 29 Mar 2023, 5:42 PM
    Hi Justin,

    We've been using Generico for a while now. It's been really helpful in our Moodle Instance, so much so it's a pretty integral part in how our users view and interact with the VLE.

    We're looking to move over to Workplace soon, and while the general consensus is "If it works on Moodle 4 it should be fine for Workplace", I didn't know if you could confirm if Generico has been used in any Workplace instances?

    Cheers,

    Richard
  • Justin Hunt
    Thu, 30 Mar 2023, 2:40 PM
    I am sure it has been used in Workplace, but I have not had any communications about that. We are more likely to get notified if it doesn't work, ironically.
  • Richard Newton
    Tue, 15 Aug 2023, 6:17 PM
    Hi Justin,

    As our Moodle site grows, we're becoming increasingly reliant on Generico for some core functionality. It's been going really well.

    A couple templates we have rely on returning only one value from a SQL query, however, I'm still having the issue when a value ends in a x.x0 or x.x. Eg, both 1.20 and 1.2 are thought of as the same. So if I have them somewhere in the same column, I'll get an error.

    I was getting round it by adding a space after one of the number (for Generico to pass that?) but that doesn't seem to be 100% effective. The column in the database is a varchar (like most of the columns that I need to pull up a number/letter number reference).

    Is this something I'm not doing correctly my end? Or is there a way to get Generico to send the trailing 0 to the SQL command?

    Cheers again,

    Richard
  • Justin Hunt
    Wed, 16 Aug 2023, 9:50 PM
    Hi Richard, I am sure that can be worked out somehow within the template. But without looking at it, it is hard to say for sure. And I am not sure I have time to look at it. But you should post queries like this here: https://moodle.org/mod/forum/discuss.php?d=261896
    Then you can attach your template bundle for me (or others) to look at.
  • Dave Foord
    Tue, 12 Dec 2023, 4:21 PM
    I haven't used Generico filters before, but am liking what I see...

    I have a need to display a countdown timer for an upcoming exam, and found this post https://moodle.org/mod/forum/discuss.php?d=324771#p1309563 which uses Generico filters to acheive just this. I recognise that this post was written a few years ago, and the filter templates now have more boxes - and I have added the relevant bits to the relevant boxes (e.g. main code into one box, css into another, and javascript into the javascript box) - but this isn't quite working - I get the boxes displayed, but no text within them. Has anyone got a countdown timer working more recently, and can point me to the code?
  • Laurent Dairaine
    Sun, 3 Mar 2024, 6:10 AM
    Hi, thanks for this great plugin. Is there any way to get the value of a dropdown custom field ? I can only get the index value. e.g, a Course dropdown custom field named level is defined with 3 value 1: Beginner, 2:Intermediate, 3: Advanced. With @@COURSE:level@@ return "2", but I would like to get "Intermediate".
  • Justin Hunt
    Sun, 3 Mar 2024, 9:57 AM
    HI Laurent. I tried that and I got the same result as you. The value of the custom variable internally is not "intermediate" but "2" (which is its index in the drop down list). I had a look to see how to get drop down list values from custom fields but it would require a bit more work than I have time for now. So in the short term, you are best to use javascript to do this. I made a template for you but I can't post anything here. You need to create forum post and I will add it as a reply there. Do that here: https://moodle.org/mod/forum/discuss.php?d=261896
1 2 3 4 5 6 7
Please login to post comments