Use Bootstrap in my plugin.

Re: Use Bootstrap in my plugin.

by Lina Ahmed Kamal -
Number of replies: 3
Thank you I will check this out. So nobody uses the html_writer() function anymore? I'm using code from another plugin so that's how it was done.
In reply to Lina Ahmed Kamal

Re: Use Bootstrap in my plugin.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I have to be careful here... I would suggest that it may not be the best choice for a new development.
Average of ratings: Useful (1)
In reply to Lina Ahmed Kamal

Re: Use Bootstrap in my plugin.

by Richard Jones -
Picture of Plugin developers Picture of Testers
Hi Lina

It would be difficult to say nobody is using html_writer anymore and perhaps difficult to avoid seeing it in Moodle code. However, here is an example of the sort of code Howard is talking about that uses a custom class and a Mustache template together with the core renderer ($OUTPUT). As a person recently on this journey also I hope this helps, note the code is in the bootstrap_eg branch.

https://github.com/richardjonesnz/moodle-block_simpleblock/tree/bootstrap_eg

Kind regards
Richard
Average of ratings: Useful (1)
In reply to Richard Jones

Re: Use Bootstrap in my plugin.

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think it depends on the circumstances. There are two extremes where the choice is clear, and a big grey area between those two:

  • If you are displaying a chunk of user-visible stuff (e.g. a forum post) then it is definitely better to use a template (with a templateable object) as Richard demonstrates. This is probably the more common case to be in.
  • If you are outputting something highly technical, with lots of attributes whose values have to be computed in PHP (e.g. the submit button that is part of the display of questions with interactive behaviours, https://github.com/moodle/moodle/blob/master/question/behaviour/rendererbase.php#L229) then I think the html_writer code is the most readable option. Some uses of html_writer::link are also the best way to handle it.

One of my favourite quotes is:

"The history of web development has been finding increasingly complicated way to concatenate strings."

So true!

Average of ratings: Useful (1)