Adding a content filter

Adding a content filter

by Tonnie Oostbeek -
Number of replies: 3

Hello All,


I am looking into the possibilities of Moodle to be used as an LMS for the company I work at.

So far we are impressed by the possibilities Moodle has to offer.

As an international operating company especially the multi-language filter is great.

There is one thing I could not get to work. Is it possible to filter the content based on a User Profile field. So that simular to the language filter i could place content like {locationfilter XX} Content X here {Locationfilter} { locationfilter YY} Content Y here {locationfilter} Locationfilter should be filtered based on a additional value on the user profile field

Average of ratings: -
In reply to Tonnie Oostbeek

Re: Adding a content filter

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

HI Tonnie

This could be done with the Generico filter. It would look pretty much like that on the page, but you would need to make a custom template. Not very hard but a little bit hard. Anyway see here:

https://moodle.org/plugins/filter_generico

And for more detailed info on creating templates see here. It's for the Poodll filter but the filter string and general information is the same for Generico :

https://poodll.freshdesk.com/a/solutions/articles/19000083258



In reply to Justin Hunt

Re: Adding a content filter

by Tonnie Oostbeek -

Hello Justin,


Thank you for your reply.


I do not see how I can set up Generico filter to provide for this functionality.


As far as I can see I can replace a string in this format @@String@@ and replace it with a different text from the template.

But I want the following. If USER:Location is XX then use {Location xx} This text {Location} if USER:Location = YY then use {Location yy} This text {Location}



In reply to Tonnie Oostbeek

Re: Adding a content filter

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Generico is a general tool for implementing custom filters from css/js/html templates, without having to wrote a whole new plugin. So perhaps the solution in this case is a little roundabout but it might be ok. You would  want to tailor the following example to suit your use case. But if you look at the template it is quite straightforward.

Custom profile field: haircolor


Generico Template: haircolor

(Custom JS script field)

<span id="@@AUTOID@@" style="display: none">
<script>
if('@@color@@' == '@@USER:haircolor@@'){
document.getElementById('@@AUTOID@@').style='display: block';
}
</script>


Generico filter string (on a page, in an html block etc)

A message for red haired people:
 {GENERICO:type="haircolor",color="red"}You are special{GENERICO:type="haircolor_end"}

I have attached the haircolor template bundle if you want to try it out yourself.