Jump to content

Module:ListSubpages: Difference between revisions

From Monster Girl Encyclopedia
imported>Xena
Module for listing subpages
 
imported>Xena
Fixed an issue
Line 5: Line 5:
function p.list( frame )
function p.list( frame )
     local page = frame.args[1] or frame.args['page'] or frame:callParserFunction('TOPLEVELPAGE')
     local page = frame.args[1] or frame.args['page'] or mw.text.split(tostring(mw.title.getCurrentTitle()), '/', true)[1]
    page = frame:callParserFunction('TOPLEVELPAGE', {page})
local allSubpages = frame:callParserFunction('SUBPAGES', { page, sep = "|" })
local allSubpages = frame:callParserFunction('SUBPAGES', { page, sep = "|" })
allSubpages = mw.text.split(allSubpages, "|")
allSubpages = mw.text.split(allSubpages, "|")
Line 16: Line 15:
     result[#result+1] = [==[|<span style="color:white;">Main</span>]]</div>]==]
     result[#result+1] = [==[|<span style="color:white;">Main</span>]]</div>]==]
-- add subpages
if #allSubpages[1] > 0 then for i = 1, #allSubpages do
if #allSubpages[1] > 0 then for i = 1, #allSubpages do
result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==]
result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==]

Revision as of 08:56, 4 September 2022

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

local p = {} --p stands for package



function p.list( frame )
	
    local page = frame.args[1] or frame.args['page'] or mw.text.split(tostring(mw.title.getCurrentTitle()), '/', true)[1]
	local allSubpages = frame:callParserFunction('SUBPAGES', { page, sep = "|" })
	allSubpages = mw.text.split(allSubpages, "|")
	result = {}
	
	-- add main page
	result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==]
    result[#result+1] = page
    result[#result+1] = [==[|<span style="color:white;">Main</span>]]</div>]==]
	
	-- add subpages
	if #allSubpages[1] > 0 then for i = 1, #allSubpages do
		result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==]
    	result[#result+1] = allSubpages[i]
    	result[#result+1] = [==[|<span style="color:white;">]==]
		result[#result+1] = string.sub( allSubpages[i], #page+2 )
		result[#result+1] = '</span>]]</div>'
	end end

    return table.concat(result)

end


return p