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
mNo edit summary |
(Test for wrapping the sources in their own divs) |
||
| Line 7: | Line 7: | ||
local result = "" | local result = "" | ||
-- | -- If no items are found, add "Nothing" to the list | ||
if #items == 0 then | if #items == 0 then | ||
items = {"Nothing"} | items = {"Nothing"} | ||
end | end | ||
-- Iterate over the items and create a div element for each | |||
for i, item in ipairs(items) do | for i, item in ipairs(items) do | ||
item = mw.text.trim(item) | 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 | if item == "Nothing" then | ||
imageName = "X" | imageName = "X" | ||
end | end | ||
result = result .. '[[File:' .. imageName .. '.png|24px|link=]] [[' .. item .. ']]<br />' | -- 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=]][[' .. item .. ']]' | |||
-- Close the div element | |||
result = result .. '</div><br />\n' | |||
-- result = result .. '<div class="item_source">[[File:' .. imageName .. '.png|24px|link=]] [[' .. item .. ']]</div><br />\n' | |||
end | end | ||
Revision as of 11:03, 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 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
-- 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=]][[' .. item .. ']]'
-- Close the div element
result = result .. '</div><br />\n'
-- result = result .. '<div class="item_source">[[File:' .. imageName .. '.png|24px|link=]] [[' .. item .. ']]</div><br />\n'
end
return result
end
return p