Module:Navbox or wikitable
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | 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 module depends on the following other modules: |
This module can be used to create a navbox which can be optionally rendered as a wikitable. This is useful when one would like to have the content of a navbox rendered in the middle of an article as a regular table.
Usage
Take any navbox and replace
{{navbox
with
{{#invoke:navbox or wikitable|main|navbox={{{navbox|}}}
By default, the navbox will render as a navbox, but if |navbox=no
then it will render as a wikitable.
require('strict')
local p = {}
function p.main(frame)
local is_table = frame.args['table'] or ''
-- If this is not a table, then jump straight over to the navbox module
if ( is_table ~= '' ) then
return require('Module:Navbox').navbox(frame, 'navbox')
end
local args = frame.args
-- get the group and list numbers
local groups, lists, nums = {}, {}, {}
for k,v in pairs(args) do
if type(k) == 'string' and k:match('^list[0-9][0-9]*$') then
local i = mw.ustring.gsub(k,'^list([0-9][0-9]*)$', '%1')
i = tonumber(i)
if lists[i] == nil and groups[i] == nil then
table.insert(nums, i)
end
lists[i] = v
elseif type(k) == 'string' and k:match('^group[0-9][0-9]*$') then
local i = mw.ustring.gsub(k,'^group([0-9][0-9]*)$', '%1')
i = tonumber(i)
if groups[i] == nil and lists[i] == nil then
table.insert(nums, i)
end
groups[i] = v
end
end
-- sort the group and list numbers
table.sort(nums)
-- generate the table
local tbl = mw.html.create('table')
:addClass('wikitable')
:addClass('args.bodyclass')
local navbar = require('Module:Navbar')._navbar
tbl:tag('caption')
:wikitext(args.title or '')
:wikitext(navbar{
['name'] = args.name,
['mini'] = 1,
['brackets'] = 1,
['style'] = 'float:right'
})
if args['above'] then
local row = tbl:tag('tr')
row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
:wikitext(args['above'])
end
for ni = 1, #nums do
local i = nums[ni]
if args['group' .. i] and args['list' .. i] then
local row = tbl:tag('tr')
row:tag('th')
:attr('scope', 'row')
:css('font-weight', 'normal')
:wikitext(args['group' .. i])
row:tag('td')
:addClass(args.listclass)
:wikitext('\n' .. args['list' .. i])
elseif args['list' .. i] then
local row = tbl:tag('tr')
row:tag('td')
:addClass(args.listclass)
:css('text-align', 'center')
:wikitext('\n' .. args['list' .. i])
end
end
if args['below'] then
local row = tbl:tag('tr')
row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
:wikitext(args['below'])
end
return tbl
end
return p