Home
Random
Log in
Settings
About Brighter Shores Wiki
Disclaimers
Search
Editing
Module:Infobox/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{documentation}} {{ToC|right}} ==Creating a template step-by-step== ===Import Module:Infobox and Module:Param Parse=== <syntaxhighlight lang="lua"> local Infobox = require('Module:Infobox') local parse = require('Module:Param Parse') </syntaxhighlight> ===Unpack the frame arguments from the Template=== <syntaxhighlight lang="lua"> local p = {} function p.main(frame) local args = frame:getParent().args ... </syntaxhighlight> ===Setup the Module config settings=== <syntaxhighlight lang="lua"> local config = { infobox_name = 'Scenery', class = {Infobox.smw_param('episode')}, -- Add css class with episode name to colorize Infobox } </syntaxhighlight> ===Map your arguments to parsing functions=== {{Main|Module:Param Parse}} Use the params in [[Module:Param Parse]] to validate and format the data - feel free to create your own new params in [[Module:Param Parse]]. <syntaxhighlight lang="lua"> local params = { parse.name, parse.image, {name = 'description', func = parse.has_content, smw_property = 'Description'}, -- Custom param parse.episode, ... } </syntaxhighlight> ===Define an Infobox object=== {{Main|Module:Infobox#new}} <syntaxhighlight lang="lua"> local infobox = Infobox.new(config, params, args) </syntaxhighlight> ===Create your table=== {{Main|Module:Infobox#create}} <syntaxhighlight lang="lua"> infobox :add_row{ {tag='th', content=Infobox.param('name'), class='infobox-header', colspan='20'}, } :add_row{ {tag='td', content=Infobox.param('image'), class='infobox-image', colspan='20'}, } :pad("20") :add_row{ {tag='td', content='Info', class='infobox-subheader', colspan='20'}, } :pad("20") :add_row{ {tag='th', content='Description', colspan="6"}, {tag='td', content=Infobox.param('description'), colspan="14"}, } :add_row{ {tag='th', content='[[Episode]]', colspan="6"}, {tag='td', content=Infobox.param('episode'), colspan="14"}, } ... </syntaxhighlight> ===You're done!=== <syntaxhighlight lang="lua"> return infobox end return p </syntaxhighlight> ==Functions== === Special params === You don't need to do anything about these special parameters, but they may be used as parameters within the Template: {| class="wikitable" ! param ! explanation |- | version1, version2, version3 | Button label and SMW name for each switch version of the infobox |- | default_version | The default version to display when the page is loaded |- | version | If there is only a single version, you can use version to set the SMW name (default SMW name is "DEFAULT") |} === Referring to params === Each parameter can have a different value for each version. In addition, there are 3 different representations of each value. Therefore, a parameter must be accessed via one of the 3 helper functions: {| class="wikitable" ! helper function ! example ! explanation |- | Infobox.raw_param(name) | "1000" | Raw value as passed by the Template |- | Infobox.param(name) | "1,000" | Value formatted for display in the Infobox |- | Infobox.smw_param(name) | 1000 | Value formatted to be saved as an SMW property |} === Infobox.new(config, params, args) === Creates a new infobox. Automatically parses the arguments, creates SMW subobjects and adds categories. <syntaxhighlight lang="lua"> local infobox = Infobox.new(config, params, args) </syntaxhighlight> ==== config ==== There are only 3 parameters for config <syntaxhighlight lang="lua"> local config = { infobox_name = 'Scenery', -- mandatory unique identifier for css class = {'CustomClass', Infobox.smw_param('episode')} -- optional, defaults to {}. Adds css classes to infobox table: {'infobox-CustomClass', 'infobox-[default version parameter's value]'} max_buttons = 6, -- optional, defaults to 6, max number of switch buttons before using a dropdown list instead } </syntaxhighlight> ==== params ==== A list of parameters to be processed by the Infobox module <syntaxhighlight lang="lua"> local params = { { name = <param>, func = <func>, ... }, ... } </syntaxhighlight> {| class="wikitable" ! key ! value |- | name | parameter name as used in the Template |- | func | A function in [[Module:Param Parse]] to validate and process the Template argument. You can also use a local function, but this is not recommended. If func is a function, will call func(Infobox.raw_param(name)): <syntaxhighlight lang="lua"> {name = <param>, func = <func>, ... }, </syntaxhighlight> If func is a table, it takes the following parameters: <syntaxhighlight lang="lua"> {name = <param>, func = { name = <func>, params = <func_params>}, ... }, </syntaxhighlight> {| class="wikitable" | name | function in [[Module:Param Parse]] |- | params | a list of parameters to pass the the function, in the form of constants, or Infobox.raw_param(name), Infobox.param(name), Infobox.smw_param(name) |} |- | empty (optional) | text to display in the infobox if func returns nil; defaults to "? (edit)" |- | category_never (optional) | category to add if func returns nil for all versions |- | category_partial (optional) | category to add if func returns nil for some versions, but a value for other versions |- | category_incomplete (optional) | category to add if func returns nil for at least 1 version (i.e. category_never and category_partial combined) |- | category_complete (optional) | category to add if func returns a value for all versions |- | smw_property (optional) | if this string is defined, the parameter will be saved into SMW |- | smw_func (optional) | function to validate and process the Template argument to save into SMW. func is used by default if smw_func is not defined |} ==== args ==== Arguments passed via the Template <syntaxhighlight lang="lua"> local args = frame:getParent().args </syntaxhighlight> === infobox:is_param_defined(param) === Used to conditionally display a line in the infobox <syntaxhighlight lang="lua"> infobox:add_row{ {tag='th', content=Infobox.param('name'), class='infobox.subheader', colspan='2'}, } if infobox:is_param_defined(Infobox.param('owner')) > 0 then infobox:add_row{ {tag='td', content='[[Owner]]'}, {tag='td', content=Infobox.param('owner')}, } end </syntaxhighlight> {| class="wikitable" | param | a parameter referenced via Infobox.raw_param(name), Infobox.param(name) or Infobox.smw_param(name) |- | Returns | 0 if param is never defined 1 if param is defined for a fraction of the versions 2 if param is defined for all versions |} === Infobox:add_row(...) === Adds a row to the infobox table. Parameter should be a table of cells: <syntaxhighlight lang="lua"> infobox:add_row{ {tag='td', content='[[Cell1]]', ...}, {tag='td', content=Infobox.param('param'), ...}, {tag='td', content='[[Cell3]]', ...}, ... addClass = 'row-class' } </syntaxhighlight> Each cell should have a set of key-values, of which only the tag and content are mandatory: {| class="wikitable" ! key ! value |- | tag | 'td' or 'th' |- | content | a string or Infobox.param(name), Infobox.raw_param(name), Infobox.smw_param(name) |- | attr (optional) | a table of attributes to add to the cell mw.html:attr({ arg1 = '1', ... }) |- | css (optional) | a table of css to add to the cell mw.html:css({ arg1 = '1', ... }) |- | class (optional) | a string with a class to add, or a table of classes to add. '''infobox-header''', '''infobox-subheader''' and '''infobox-image''' are commonly used. mw.html:addClass(...) |- | rowspan (optional) | Set the cell rowspan mw.html:attr('rowspan',arg) |- | rowspan (optional) | Set the cell colspan mw.html:attr('colspan',arg) |- | title (optional) | Set the cell title mw.html:attr('title',arg) |} === Infobox:pad(colspan, class) === Adds a blank row of padding spanning the given number of columns. Will always add the class '''infobox-padding''', but can optionally add another class: <syntaxhighlight lang="lua"> infobox:pad("10", class=<class>) </syntaxhighlight> === Infobox:addClass(class) === Adds a class to the entire table <syntaxhighlight lang="lua"> infobox:addClass(class) </syntaxhighlight> === Infobox:dump() === Logs all the values into the Debug console for debugging purposes. You can also dump all the values in an Infobox template by setting a template parameter "__dump = Yes".
Summary:
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
Brighter Shores:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Template:DependencyList
(
edit
)
Template:DependencyList/doc
(
edit
)
Template:Documentation
(
edit
)
Template:Extension DPL
(
edit
)
Template:Main
(
edit
)
Template:ToC
(
edit
)
Module:Array
(
edit
)
Module:DPLlua
(
edit
)
Module:DependencyList
(
edit
)
Module:Documentation
(
edit
)
Module:Edit button
(
edit
)
Module:Hatnote
(
edit
)
Module:Infobox
(
edit
)
Module:Infobox Class
(
edit
)
Module:Infobox Emote
(
edit
)
Module:Infobox Episode
(
edit
)
Module:Infobox Item
(
edit
)
Module:Infobox Monster
(
edit
)
Module:Infobox NPC
(
edit
)
Module:Infobox Profession
(
edit
)
Module:Infobox Quest
(
edit
)
Module:Infobox Room
(
edit
)
Module:Infobox Scenery
(
edit
)
Module:Infobox Shop
(
edit
)
Module:Infobox Skill Node
(
edit
)
Module:Infobox Spell
(
edit
)
Module:Infobox Venture
(
edit
)
Module:Main article
(
edit
)
Module:Param Parse
(
edit
)
Module:Paramtest
(
edit
)
Module:SMW Utils
(
edit
)
Module:Tooltip
(
edit
)
Module:Yesno
(
view source
) (semi-protected)
This page is a member of a hidden category:
Category:Pages using DynamicPageList3 parser function