Module:Sidebar: Difference between revisions
Jump to navigation
Jump to search
Created page with "local getArgs = require("Module:Arguments").getArgs local p = {} -- Not to be confused with the infobox; the sidebar only has one column and is a -- different color. Some infobox-ish templates use that style -- Not to be confused with the sidebox either. -- TODO: add float option? -- "Main" function function p._sidebar(args) local title = args["Title" ] local header = args["Header"] local rows = args["Rows" ] local footer = args["Footer"] -- Helper functi..." |
mNo edit summary |
||
| Line 72: | Line 72: | ||
local rows = {} | local rows = {} | ||
for i = 1, 20 do | for i = 1, 20 do | ||
local key = string.format("Row %d") | local key = string.format("Row %d", i) | ||
local row = args[key] | local row = args[key] | ||
if row then table.insert(rows, row) end | if row then table.insert(rows, row) end | ||
Revision as of 12:07, 11 October 2025
- This module implements a metatemplate, and may be invoked by templates using its corresponding template Template:Sidebar, or used directly from other modules.
Module:Sidebar is a module that implements the {{Sidebar}} template. Sidebar templates can be made by using the template or by calling the _sidebar function from another module.
On templates, you can create a sidebar by using {{Sidebar}}, which calls this module's wrapper function.
local sidebar = require("Module:Sidebar")._sidebar to create a sidebar.
| Introspection summary for Module:Sidebar | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local getArgs = require("Module:Arguments").getArgs
local p = {}
-- Not to be confused with the infobox; the sidebar only has one column and is a
-- different color. Some infobox-ish templates use that style
-- Not to be confused with the sidebox either.
-- TODO: add float option?
-- "Main" function
function p._sidebar(args)
local title = args["Title" ]
local header = args["Header"]
local rows = args["Rows" ]
local footer = args["Footer"]
-- Helper function; title
function sidebar_title()
local lines = {}
table.insert("|-")
table.insert(string.format("! %s", title))
return table.concat(lines, "\n")
end
-- Helper function; row
function sidebar_row(row_content)
local lines = {}
table.insert("|-")
table.insert(string.format("| %s", row_content))
return table.concat(lines, "\n")
end
-- Helper function; header/footer
function header_footer_row(row_content)
local lines = {}
table.insert("|-")
table.insert(string.format('| style="font-size: 80%;" | %s', row_content))
return table.concat(lines, "\n")
end
-- Boilerplate and start of table
local lines = {}
table.insert(lines, '<div class="toccolours" style="float: right; margin: 0px 0px 4px 4px; text-align: center">')
table.insert(lines, '{| class="none"')
table.insert(lines, "|-")
-- Title
if title then table.insert(lines, sidebar_title()) end
-- Header
if header then table.insert(lines, header_footer_row(header)) end
-- Rows
for i = 1, #rows do table.insert(lines, sidebar_row(rows[i])) end
-- Footer
if footer then table.insert(lines, header_footer_row(footer)) end
-- End of table
table.insert(lines, "|}")
return table.concat(lines, "\n")
end
-- Wrapper function
function p.sidebar(frame)
local args = getArgs(frame)
-- Preprocess rows
local rows = {}
for i = 1, 20 do
local key = string.format("Row %d", i)
local row = args[key]
if row then table.insert(rows, row) end
args[key] = nil
end
args["Rows"] = rows
return frame:preprocess(p._sidebar(args))
end
return p