Bogleheads:Sandbox

Testing nested Navboxes
The following wikitext creates a usable nested Navbox on Wikipedia:Special:ExpandTemplates, but misbehaves on our wiki. Minimum failing example:

Result:

The child Navbox displays simultaneously in both Desktop and Mobile formats, but only one format or the other should display. This happens because the output of Module:NavboxMobile with  breaks   restrictions placed around it in Template:Navbox.

Test:
 * Before. This should only display in mobile browsers, but breaks the restriction. After.

Result (if viewed in Desktop):
 * Before. This should only display in mobile browsers, but breaks the restriction. After.

Calling  with   triggers this problem. Its output starts with, and the leading   closes the opening. It then goes on to end with an opening  of its own.

Notably, this is not specific to. It is also the case with, which does the same thing, and so will trigger the problem in the other direction (that is, if viewed on Mobile). The cause of the problem is MediaWiki's poor design and implementation of child Navboxes. It is fragile and brittle.

The solution is to enclose each invocation of Module:Navbox and Module:NavboxMobile in Template:Navbox inside a separate.

Example:
 * Before. This should only display in mobile browsers, but breaks the restriction. After.

Result:
 * Before. This should only display in mobile browsers, but breaks the restriction. After.

The TL;DR is that the following, starting at line 506 of Module:Navbox (and unavoidably, because it has to match, also present in Module:NavboxMobile, starting at line 523), is a boneheaded way of handling child Navboxes: -- We assume that this navbox is being rendered in a list cell of a -- parent navbox, and is therefore inside a div with padding:0em 0.25em. -- We start with a to avoid the padding being applied, and at the -- end add a to balance out the parent's res :wikitext(' ') :node(tbl) :wikitext(' ')

After template bug fix
The template below is implemented per the documentation.