Your Moodle version

Filters: Generico

filter_generico
Maintained by Picture of Justin Hunt Justin Hunt
Generico is a simple filter for creating templates of code snippets and text that can be inserted into Moodle text areas.
1k
137
7
Moodle 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8

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 up to twenty 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. 



USAGE

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.


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

{GENERICO:type=youtube,id=ABC12345678}


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

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



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

Show comments
  • Picture of David Mudrák
    Thu, Jun 19, 2014, 5:35 AM
    Thanks Justin for contributing this interesting filter. I can imagine there are situations when it can come as really handy tool. I
    am going to approve it now.

    While reviewing the code, I spotted that the function generico_fetch_filter_properties() violates the frankenstyle naming
    convention. It should start with filter_generico_ prefix. Also, I think that at the top of the filter_generico::filter() there could
    be check added for passed empty string. I would personally perform a simple strpos() test for the {GENERICO: substring there too.
    The strpos() is pretty quick and it would save PHP from executing preg_replace_callback() that often.

    There is a comment in filter_generico_callback() that refers to poodllresourcelib. I suspect that was just left after a copy/paste
    from another plugin?

    You may want to address these comments in a future version of your code. Said that, you are cleared to land now - welcome to plugins
    directory!
  • Picture of Justin Hunt
    Thu, Jun 19, 2014, 9:40 AM
    Thanks David. That is good news. I will make those changes soon. Nice to get the feedback. Keep up the good work.
  • Picture of Markus L. Blömeke
    Thu, Jul 24, 2014, 5:02 PM
    Hey, Justin, great tool – thanks for contributing!

    I am asking myself whether it can be used for even simpler auto-replacement operations. E.g. for this: Whenever someone types "@@@" in a posting's heading, the text would be replaced by "APPROVED:".

    Would there be some syntax for that?
  • Picture of Justin Hunt
    Fri, Jul 25, 2014, 5:25 AM
    Right now there are no settings that would make something like that work. The most minimal template, would still be a it wordy
    eg
    {GENERICO:type=T}
  • Picture of Sebastien Gendry
    Fri, Feb 6, 2015, 4:29 AM
    I love this plugin! It's very simple to use and extremely handy.

    I have a question about

    {collapsible}[read more...]
    Your text/HTML here.
    {collapsible}

    This code hides the content by default. Is there a way to have it open, e.g., open="yes/no"?
  • Picture of Justin Hunt
    Fri, Feb 6, 2015, 9:00 AM
    Hi Sebastien,
    I think you are referring to the "toggle" preset? So something like:
    {GENERICO:type="toggle" text="read more .."}
    blah blah blah blah
    {GENERICO:type="toggle_end"}

    You would just alter the template where it says:

    To be open by default always ... you would change it to this:

    To have a template variable which allows you alter the default when adding the string:
    And then in the template defaults add:
    open=block

    "yes/no" could work but you would have to write some javascript to turn yes and no into "block" and "none." Its simpler to just remember: none or block

    In the toggle example I tried to give a simple example of using YUI from a template. It would certainly be possible to add a "supertoggle" with easy to set defaults and animation etc. But then it wouldn't be a simple example ...
  • Picture of Justin Hunt
    Fri, Feb 6, 2015, 9:07 AM
    GASP. Moodle stripped out my code examples. Let that be a warning to ye all. Post in the forum if possible.

    https://moodle.org/mod/forum/discuss.php?d=261896#p1202120
  • Picture of Sebastien Gendry
    Tue, Mar 10, 2015, 4:43 AM
  • Picture of David Swan
    Thu, Jun 18, 2015, 10:39 PM
    Hi will there be a version released for moodle 2.9 once I install this i get syntax error "unexpect end of line" when trying to get into site adminstration.
  • Picture of Justin Hunt
    Sun, Jun 21, 2015, 2:14 PM
    David. I posted also in the forum where you were introduced to Generico. So I think maybe you have moved on anyway. But I have tested Generico on Moodle 2.9 without any issues. Are you sure that error is coming from Generico? If you remove Generico, did he error go away? If so it could have been a failed FTP upload. I would try to upload Generico again and see if the problem clears up.
Please login to post comments