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
(Remove the BR) |
(Update to avoid linking to "Nothing" as a page) |
||
Line 3: | Line 3: | ||
function p.displayFoundIn(frame) | function p.displayFoundIn(frame) | ||
-- Get the first argument passed to the module | |||
local foundIn = frame.args[1] | local foundIn = frame.args[1] | ||
-- Split the string into a table based on the comma delimiter | |||
local items = mw.text.split(foundIn, ',') | local items = mw.text.split(foundIn, ',') | ||
-- Initialize the result string | |||
local result = "" | local result = "" | ||
Line 21: | Line 24: | ||
if item == "Nothing" then | if item == "Nothing" then | ||
imageName = "X" | imageName = "X" | ||
end | |||
local link_name = item | |||
if item ~= "Nothing" then | |||
link_name = "[[" .. item .. "]]" | |||
end | end | ||
Line 26: | Line 34: | ||
result = result .. '<div class="item_source" style="display: flex; gap: 5px;">' | result = result .. '<div class="item_source" style="display: flex; gap: 5px;">' | ||
-- Add the image and item name to the div element | -- Add the image and item name to the div element | ||
result = result .. '[[File:' .. imageName .. '.png|24px|link=]] | result = result .. '[[File:' .. imageName .. '.png|24px|link=]]' .. link_name | ||
-- Close the div element | -- Close the div element | ||
result = result .. ' | result = result .. '</div><br />\n' | ||
end | end | ||
Revision as of 07:42, 1 July 2024
Documentation for this module may be created at Module:InfoboxModuleTest/doc
-- Module:InfoboxTestModule local p = {} function p.displayFoundIn(frame) -- Get the first argument passed to the module local foundIn = frame.args[1] -- Split the string into a table based on the comma delimiter local items = mw.text.split(foundIn, ',') -- Initialize the result string local result = "" -- If no items are found, add "Nothing" to the list if #items == 0 then items = {"Nothing"} end -- Iterate over the items and create a div element for each for i, item in ipairs(items) do item = mw.text.trim(item) -- Create a version of the item name that can be used as an image name local imageName = string.gsub(item, " ", "_") -- If the item is "Nothing", use the X image if item == "Nothing" then imageName = "X" end local link_name = item if item ~= "Nothing" then link_name = "[[" .. item .. "]]" end -- Open the div element result = result .. '<div class="item_source" style="display: flex; gap: 5px;">' -- Add the image and item name to the div element result = result .. '[[File:' .. imageName .. '.png|24px|link=]]' .. link_name -- Close the div element result = result .. '</div><br />\n' end return result end return p