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.