Displaying tables with mustache templates?

Displaying tables with mustache templates?

by Frederic Nevers -
Number of replies: 2

I am developing a new activity module, and would like to make use of the Mustache templating engine. I have managed to create different pages for my module (e.g. view.php, add.php, etc.) and managed to pass basic data to the renderables. It seems as though the renderer also works fine, as the correct data is displayed on the resulting page (using a very basic Mustache template - similar to the one shown in the documentation). 

I am a bit confused as to what extent I should be using Mustache templates to display and organise data. Say for example, I have a DB query that returns a bunch of records, which ideally should be displayed in a table. Do I generate the table in my Mustache template using the resulting array? Or should I do it another way? 

Another example would be form elements. How do I display a form element using the form API? How does that tie in with Mustache templates?

Should the entire page be organised and displayed using the templates (aside from headers, footers and the rest of the 'core' Moodle stuff). If so, does that mean the html_writer class is now unnecessary or redundant?

Apologies if the above are stupid questions, but I am having a really hard time figuring things out from the documentation, or the few examples in the Moodle core code. 

Cheers, 

Fred

Average of ratings: -
In reply to Frederic Nevers

Re: Displaying tables with mustache templates?

by Damyon Wiese -
It is definitely in the plans to create a convenient way to display tables and forms with templates. E.g. all the current moodleforms elements will have renderers/templates added to them, so they can be customised by themes and rendered from javascript. We just haven't had time to actually do this yet.

For now - I would advise you do use templates as much as they are convenient.
In reply to Damyon Wiese

Re: Displaying tables with mustache templates?

by Frederic Nevers -

Thanks Damyon.  

I think I'll steer clear from templates until all of the heavy lifting has been done, as I see little benefit for my current project. I'll update it later (much later, likely smile  

Cheers, 

Fred