Module:PageTabs org

From TwogPedia
Revision as of 11:44, 19 October 2022 by Couchor (talk | contribs) (Created page with "local cargo = mw.ext.cargo local PageTabs = {} function PageTabs.main(frame) local currentTitle = mw.title.getCurrentTitle().text local empty = true local titleSplit = mw.text.split(currentTitle, '/') local org = #titleSplit > 1 and titleSplit[2] or currentTitle -- Check if there are any interviews for this page local tables = 'Teams' local fields = '_pageName, org' local cargoArgs = { where = 'org="' .. org .. '"' } local results = cargo.query(tables, f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:PageTabs org/doc

local cargo = mw.ext.cargo

local PageTabs = {}

function PageTabs.main(frame)
	local currentTitle = mw.title.getCurrentTitle().text
	local empty = true
	local titleSplit = mw.text.split(currentTitle, '/')
	
	local org = #titleSplit > 1 and titleSplit[2] or currentTitle

	-- Check if there are any interviews for this page
	local tables = 'Teams'
	local fields = '_pageName, org'
	local cargoArgs = {
		where = 'org="' .. org .. '"'
	}
	local results = cargo.query(tables, fields, cargoArgs)
	local tabArgs = {}
	tabArgs.name1='Organization'
	tabArgs.link1 = org

	if #results > 0 then
		empty = false
		for r = 2, #results do
			local result = results[r]
			local resultSplit = mw.text.split(result._pageName, '/')
			tabArgs['name' .. tostring(r)] = resultSplit[1]
			tabArgs['link' .. tostring(r)] = resultSplit[2]
		end
	end
	
	if empty then
		return '<span class="d-none"></span>'
	else
		return frame:expandTemplate{ title = 'Tabs', args = tabArgs }
	end
	
end

return PageTabs