General developer forum

Mustache template for list item causes a mustache_lint warning

 
Picture of Kevin Wiliarty
Mustache template for list item causes a mustache_lint warning
Core developersPlugin developersTesters
I am gradually trying to phase in mustache templates for the Filtered Course List plugin. One of the templates that I would like to have is for list-item <li> elements. According to the Moodle plugin integration pre-checks, my template causes an HTML Validation warning for mustache_lint:

HTML Validation error, line 2: Element “li” not allowed as child of element “body” in this context. (Suppressing further errors from this subtree.) (ad><body><li class='block_filtered_course_list_list_item fcl-course-link'> <)

The pre-check summary page showing the warning can be viewed here:

https://moodle.org/plugins/pluginversion.php?id=14670&smurf=html#mustache

And you can see the template file that causes the warning here:

https://git.in.moodle.com/pluginsbot/moodle-plugins-snapshots/blob/c0052cca0fbfae1c48f19ad790cd8de75db2f215/blocks/filtered_course_list/templates/list_item.mustache#L1

Apparently my list-item template also causes the moodlerooms-plugin-ci to fail on Travis:

https://travis-ci.org/kwiliarty/moodle-blocks_filtered_course_list/jobs/301604525#1-1714

Is it wrong to be making a template for list items? And if it's not, is there something I should be doing differently to avoid the HTML Validation warnings and CI failures?


 
Average of ratings: -
Picture of Sam Chaffee
Re: Mustache template for list item causes a mustache_lint warning
Core developers

Hi Kevin,

It looks like this might be a bug with the linting code. Take a look at https://github.com/moodlehq/moodle-local_ci/blob/master/mustache_lint/mustache_lint.php#L201. It assumes that any html produced by a template that is not a full html document can be a direct child of the body tag. Since body is not a valid parent for an li tag you get the warning.

I don't think there is anything wrong with having a template for an li tag, but unless the linting code is changed you may have to try something else. If you aren't using the li template in more than one ul or ol you could template the entire list instead of just the list item.

HTH,

Sam


 
Average of ratings: Useful (2)
Picture of Kevin Wiliarty
Re: Mustache template for list item causes a mustache_lint warning
Core developersPlugin developersTesters

Thanks, Sam. Knowing that it's a limitation of the linter definitely helps. I think for now I'll just force that test to pass, because I believe that having an li-template is otherwise the right approach.

Cheers!

 
Average of ratings: -
Picture of David Mudrák
Re: Mustache template for list item causes a mustache_lint warning
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersPlugins guardiansTestersTranslators

I may be missing something obvious and also I haven't studied the case into details. But on your github repository I can see the rubric.mustache that correctly wraps the list items. However, in the snapshots repository which is what the code precheck uses, such a wrapper is not present. Could that be related?

 
Average of ratings: -
Picture of Kevin Wiliarty
Re: Mustache template for list item causes a mustache_lint warning
Core developersPlugin developersTesters

Hi David, there are two complications to what you're noticing. The first thing is that I have pushed new code since posing the question, and the second thing is that the rubric.mustache includes a list_item.mustache that still causes a warning in the precheck. The new snapshot is at https://git.in.moodle.com/pluginsbot/moodle-plugins-snapshots/blob/007ad633ede708abd3cddd3f3575650078b4c1bb/blocks/filtered_course_list/templates/list_item.mustache#L1.

I am now also getting a second precheck warning, again because the precheck does not consider the context into which an element is included. The new message is:

An element with “role=tab” must be contained in, or owned by, an element with “role=tablist”.

Should I be handling something differently? Or is it just a limitation of the precheck?

 
Average of ratings: -
Picture of David Mudrák
Re: Mustache template for list item causes a mustache_lint warning
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersPlugins guardiansTestersTranslators

I tend to think this is a clear bug in the prechecker.

 
Average of ratings: -