Thismodule is rated asready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
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)
Theargs 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