We are actively looking for staff to help us build the wiki. If you are interested please join our Discord server and apply.
Module:InfoboxModuleTest: Difference between revisions
Jump to navigation
Jump to search
(Hopefully add images and Nothing detection) |
m (Testing) |
||
| Line 6: | Line 6: | ||
local items = mw.text.split(foundIn, ',') | local items = mw.text.split(foundIn, ',') | ||
local result = "" | local result = "" | ||
-- if there are no items, add "Nothing" as a placeholder | -- if there are no items, add "Nothing" as a placeholder | ||
| Line 17: | Line 15: | ||
item = mw.text.trim(item) | item = mw.text.trim(item) | ||
-- generate an image name from the item name by replacing spaces with underscores | -- generate an image name from the item name by replacing spaces with underscores | ||
local imageName = string.gsub(item, " ", "_") | local imageName = string.gsub(item, " ", "_") | ||
if item == "Nothing" then | if item == "Nothing" then | ||
imageName = | imageName = "X" | ||
end | end | ||
-- construct the new format | |||
result = result .. '[[File:' .. imageName .. '.png|24px|link=]] ' .. item | |||
-- if the item | -- add a separator if not the last item | ||
if | if i < #items then | ||
result = result .. ' ' | |||
result = result .. ' | |||
end | end | ||
end | end | ||
Revision as of 09:26, 29 June 2024
Documentation for this module may be created at Module:InfoboxModuleTest/doc
-- Module:InfoboxTestModule
local p = {}
function p.displayFoundIn(frame)
local foundIn = frame.args[1]
local items = mw.text.split(foundIn, ',')
local result = ""
-- if there are no items, add "Nothing" as a placeholder
if #items == 0 then
items = {"Nothing"}
end
for i, item in ipairs(items) do
item = mw.text.trim(item)
-- generate an image name from the item name by replacing spaces with underscores
local imageName = string.gsub(item, " ", "_")
if item == "Nothing" then
imageName = "X"
end
-- construct the new format
result = result .. '[[File:' .. imageName .. '.png|24px|link=]] ' .. item
-- add a separator if not the last item
if i < #items then
result = result .. ' '
end
end
return result
end
return p