Reusing Moodle core HTML/CSS components in plugin development

Reusing Moodle core HTML/CSS components in plugin development

by Markku Riekkinen -
Number of replies: 4

Hi,

I am developing a new activity (module) plugin for Moodle 3.0 and in the user interface of the plugin, I would like to use common components such as a dropdown menu (think of Twitter Bootstrap). In my Moodle test installation with a default theme, I see that Moodle has a similar drowdown menu for editing/deleting activities in the course main page. Does Moodle provide these kinds of HTML/CSS components to plugins in a reusable way so that I could use them in my plugin as easily as using Bootstrap in other non-Moodle web apps? My plugin uses new Mustache templates, while Moodle core seems to still be reliant on the PHP renderer classes, which further complicates this matter for me. I have been unable to find Moodle documentation about its existing HTML/CSS components, which makes reusing the HTML/CSS difficult. Ideally there would documentation in the same style as Bootstrap has (very easy to read).

To summarize my question, how could I reuse Moodle HTML/CSS components in my plugin, particularly a dropdown menu? I would use such components in my Mustache templates.

As a side note (not sure if this should be another thread), I have already tried to use Twitter Bootstrap in my plugin. Some components do not work directly, since there are conflicts between Moodle and Bootstrap CSS/JS. The Bootstrap dropdown in particular does not work correctly. It seems that the way Moodle handles jQuery AMD module does not work with Bootstrap. Bootstrap has no native AMD support, but I wrapped its JS code in an AMD-style define. Nonetheless, the dropdown menu does not open on mouse click as it should. I wonder if anyone has experience in making new versions of Moodle and Bootstrap work together.

Best regards, Markku Riekkinen

Average of ratings: -
In reply to Markku Riekkinen

Re: Reusing Moodle core HTML/CSS components in plugin development

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Not sure about the first bit, but as for using bootstrap in moodle you need to bear in mind that core moodle and core Moodle Themes are still based on BS2 while the BS code snippets often found are BS3. That can be worked around (there are some BS3 themes for example) but needs to be considered.

In reply to Richard Oelmann

Re: Reusing Moodle core HTML/CSS components in plugin development

by Markku Riekkinen -

I was hoping that my solution does not depend on any specific theme, since the theme of the Moodle site is not in my control as an activity plugin developer. My main target Moodle site is the one of my institution, and they are actually using their own theme that is not available elsewhere. Hence, my plugin should not depend on having a certain theme.

In reply to Markku Riekkinen

Re: Reusing Moodle core HTML/CSS components in plugin development

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

You can use the forms interface 

https://docs.moodle.org/dev/Form_API

And you can use 

https://docs.moodle.org/dev/html_writer

In reply to Marcus Green

Re: Reusing Moodle core HTML/CSS components in plugin development

by Markku Riekkinen -

The form API does not seem appropriate to my problem since forms are intended for a different purpose (user submits input that is processed at the server). I would need a dropdown menu that is used in a kind of navbar and the menu items are links to other pages. The menu items also contain more HTML content than just text, for example badges in the side. This is possible in Twitter Bootstrap dropdown menus, while the standard HTML select element does not have such support for nested HTML elements. The Moodle html_writer does not seem to have any methods for the dropdown menus I am looking for, only the select elements.