More actions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- File: Module:ImageGrid | |||
local p = {} | local p = {} | ||
-- Function to generate the HTML for the image grid | |||
function p.renderImageGrid(frame) | function p.renderImageGrid(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local images = args['images'] or '' | local images = args['images'] or '' -- fallback to an empty string if nil | ||
local texts = args['texts'] or '' | local texts = args['texts'] or '' -- fallback to an empty string if nil | ||
-- Split the images and texts into tables | |||
local imageList = mw.text.split(images, ',') | local imageList = mw.text.split(images, ',') | ||
local textList = mw.text.split(texts, ',') | local textList = mw.text.split(texts, ',') | ||
-- Initialize the HTML container for the grid | |||
local | local html = mw.html.create('div'):addClass('image-grid-container') | ||
for i = 1, math.max(#imageList, #textList | -- Loop through the images and texts to create the grid structure | ||
local image = mw.text.trim(imageList[i] or 'Noimg.png') | for i = 1, math.max(#imageList, #textList) do | ||
local text = mw.text.trim(textList[i] or '') | -- Fallback for missing images or texts | ||
local image = mw.text.trim(imageList[i] or 'Noimg.png') -- Fallback to 'Noimg.png' if nil | |||
local text = mw.text.trim(textList[i] or '') -- Fallback to empty string if nil | |||
-- Create the image wrapper | |||
local imageWrapper = html:tag('div'):addClass('image-wrapper') | |||
-- Use the MediaWiki file syntax to render the image | |||
imageWrapper:wikitext(string.format('[[File:%s|200px]]', image)) | |||
-- Add text overlay | |||
if text ~= '' then | |||
imageWrapper:tag('div'):addClass('image-text'):wikitext(text) | |||
end | end | ||
end | end | ||
return | -- Return the generated HTML as a string | ||
return tostring(html) | |||
end | end | ||
return p | return p |
Revision as of 02:46, 17 September 2024
Documentation for this module may be created at Module:ImageGrid/doc
-- File: Module:ImageGrid
local p = {}
-- Function to generate the HTML for the image grid
function p.renderImageGrid(frame)
local args = frame:getParent().args
local images = args['images'] or '' -- fallback to an empty string if nil
local texts = args['texts'] or '' -- fallback to an empty string if nil
-- Split the images and texts into tables
local imageList = mw.text.split(images, ',')
local textList = mw.text.split(texts, ',')
-- Initialize the HTML container for the grid
local html = mw.html.create('div'):addClass('image-grid-container')
-- Loop through the images and texts to create the grid structure
for i = 1, math.max(#imageList, #textList) do
-- Fallback for missing images or texts
local image = mw.text.trim(imageList[i] or 'Noimg.png') -- Fallback to 'Noimg.png' if nil
local text = mw.text.trim(textList[i] or '') -- Fallback to empty string if nil
-- Create the image wrapper
local imageWrapper = html:tag('div'):addClass('image-wrapper')
-- Use the MediaWiki file syntax to render the image
imageWrapper:wikitext(string.format('[[File:%s|200px]]', image))
-- Add text overlay
if text ~= '' then
imageWrapper:tag('div'):addClass('image-text'):wikitext(text)
end
end
-- Return the generated HTML as a string
return tostring(html)
end
return p