Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.

Module:ItemList: Difference between revisions

From Super Fantasy Kingdom Official Wiki
Created page with "local p = {} function p.itemlist( f ) local args = f:getParent().args -- items can be one per arg or a comma separated list in one arg -- split first value at comma, e.g. from cargo list field local items = {} for v in mw.text.gsplit(args[1], ',', true) do if #v > 0 then -- ignore empty items table.insert(items, v) end end -- append other args for _,v in ipairs(args) do if _ > 1 and #v > 0 then table.insert(items, v) end end local output =..."
 
frame typo
 
(One intermediate revision by the same user not shown)
Line 22: Line 22:
local output = {}
local output = {}
for _,v in ipairs(items) do
for _,v in ipairs(items) do
table.insert(output, frame:expandTemplate{ title = 'ItemLink', args = { v } })
table.insert(output, f:expandTemplate{ title = 'ItemLink', args = { v } })
end
end
return table.concat(output, '<br>')
return table.concat(output, '<br>')
end
end
return p

Latest revision as of 21:59, 12 November 2025

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

local p = {}

function p.itemlist( f )
	local args = f:getParent().args
	
	-- items can be one per arg or a comma separated list in one arg
	-- split first value at comma, e.g. from cargo list field
	local items = {}
	for v in mw.text.gsplit(args[1], ',', true) do
		if #v > 0 then -- ignore empty items
			table.insert(items, v)
		end
	end

	-- append other args
	for _,v in ipairs(args) do 
		if _ > 1 and #v > 0 then
			table.insert(items, v)
		end
	end
	
	local output = {}
	for _,v in ipairs(items) do
		table.insert(output, f:expandTemplate{ title = 'ItemLink', args = { v } })
	end
	
	return table.concat(output, '<br>')
end

return p