Module:Side box
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 1,250,000 pages, or roughly 2% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
This module implements the {{side box}} template.
Usage from wikitext
This module cannot be used directly from wikitext. It can only be used through the {{side box}} template. Please see the template page for documentation.
Usage from Lua modules
To use this module from other Lua modules, first load the module.
localmSideBox=require('Module:Side box')
You can then generate a side box using the _main function.
mSideBox._main(args)
The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{side box}} template documentation.
localyesno=require('Module:Yesno')localp={}localfunctionmakeData(args)localdata={}-- Main table classesdata.classes={}ifyesno(args.metadata)~=falsethentable.insert(data.classes,'metadata')endifargs.positionandargs.position:lower()=='left'thentable.insert(data.classes,'side-box-left')elsetable.insert(data.classes,'side-box-right')endifargs.collapsiblethentable.insert(data.classes,'mw-collapsible')ifargs.collapsible=="collapsed"thentable.insert(data.classes,'mw-collapsed')enddata.collapsible=trueendtable.insert(data.classes,args.class)-- Imageifargs.imageandargs.image~='none'thendata.image=args.imageend-- we have to check to see if a downstream use has plainlist like-- Template:Sister_project. also it's the default. wikitext is :(ifargs.textclass=='plainlist'ornotargs.textclassthendata.textclass='plainlist'data.plainlist_templatestyles='Plainlist/styles.css'elsedata.textclass=args.textclassend-- Copy over data that does not need adjustinglocalargsToCopy={-- aria qualities'role','labelledby',-- Styles'style','textstyle','templatestyles',-- Above row'above','abovestyle',-- Body row'text','imageright',-- Below row'below',}fori,keyinipairs(argsToCopy)dodata[key]=args[key]endreturndataendlocalfunctionrenderSidebox(data)-- Renders the sidebox HTML.-- Table rootlocalroot=mw.html.create('div')root:attr('role',data.role):attr('aria-labelledby',data.labelledby):addClass('side-box')fori,classinipairs(data.classesor{})doroot:addClass(class)endifdata.stylethenroot:cssText(data.style)endlocalframe=mw.getCurrentFrame()ifdata.plainlist_templatestylesthenroot:wikitext(frame:extensionTag{name='templatestyles',args={src=data.plainlist_templatestyles}})end-- The "above" rowifdata.abovethenlocalabove=root:newline():tag('div')above:addClass('side-box-abovebelow'):newline():wikitext(data.above)ifdata.textstylethenabove:cssText(data.textstyle)endifdata.abovestylethenabove:cssText(data.abovestyle)endend-- The body rowlocalbody=root:newline():tag('div')body:addClass('side-box-flex'):addClass(data.collapsibleand'mw-collapsible-content'):newline()ifdata.imagethenbody:tag('div'):addClass('side-box-image'):wikitext(data.image)endlocaltext=body:newline():tag('div')text:addClass('side-box-text'):addClass(data.textclass)ifdata.textstylethentext:cssText(data.textstyle)endtext:wikitext(data.text)ifdata.imagerightthenbody:newline():tag('div'):addClass('side-box-imageright'):wikitext(data.imageright)end-- The below rowifdata.belowthenlocalbelow=root:newline():tag('div')below:addClass('side-box-abovebelow'):wikitext(data.below)ifdata.textstylethenbelow:cssText(data.textstyle)endendroot:newline()localtemplatestyles=''ifdata.templatestylesthentemplatestyles=frame:extensionTag{name='templatestyles',args={src=data.templatestyles}}endreturnframe:extensionTag{name='templatestyles',args={src='Module:Side box/styles.css'}}..templatestyles..tostring(root)endfunctionp._main(args)localdata=makeData(args)returnrenderSidebox(data)endfunctionp.main(frame)localorigArgs=frame:getParent().argslocalargs={}fork,vinpairs(origArgs)dov=v:match('%s*(.-)%s*$')ifv~=''thenargs[k]=vendendreturnp._main(args)endreturnp