Creating linkable tags using the multi-select form element

Creating linkable tags using the multi-select form element

de către Matthew Mazurek-
Număr de răspunsuri: 3

I'm trying to use the multi-select form element in a Moodle database to generate a list of tags. I would like these tags to link to the relevant search page displaying the filtered results.

The following template code works for singly tagged items, but fails for items with multiple tags:

<a href="/view.php?mode=list&amp;filter=Tags">Tags</a>

Is there a way to loop over items in a multi-select? Something like:

for Tag in Tags <a href="/view.php?mode=list&amp;filter=Tag">Tag</a> /for
Media notelor: -
Ca răspuns la Matthew Mazurek

Re: Creating linkable tags using the multi-select form element

de către William Lu-
Imaginea Particularly helpful Moodlers

You should have a Menu (Multi-select) field in your templates.

In 'Search Tab', make a multiple selection of your tags > save setting

Then you can get  a very long URL from your browser URL area.

Simplify it like below:

mod/data/view.php?d=30&perpage=10&order=ASC&advanced=1&f_296%5B%5D=Tag1&f_296%5B%5D=Tag2&f_296%5B%5D=Tag3

You can repeat the last part in any combination to create direct links.

Please find the attached preset example.

Ca răspuns la William Lu

Re: Creating linkable tags using the multi-select form element

de către Matthew Mazurek-

Thanks, William. I took a look at the attached files, but I don't think you've incorporated the functionality I was looking for. Ideally, these direct links would be automatically created.

I did some playing around and came up with this javascript band-aid solution:


function init() {
    var tags = document.getElementsByClassName('tags');
    for (var i=0; i<tags.length; i++) {
        tags[i].innerHTML = tags[i].innerHTML.replace(/\w[\w\s]+?(?=<br>)/g, function(n) {
            return "<a href='view.php?d=16&mode=list&perpage=10&filter=1&f_81%5B%5D="+ escape(n) + "'>" + n + "</a>";
        });
    }
};
window.onload = init;
Ca răspuns la Matthew Mazurek

Re: Creating linkable tags using the multi-select form element

de către William Lu-
Imaginea Particularly helpful Moodlers

Wow, you have a much advanced solution. 

There are some '' icons in the post, I'm guessing it might caused by the Text Editor.

Would you mind uploading and sharing your preset?

Thank you very much.

William