More actions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
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 '' | ||
local texts = args['texts'] or '' | local texts = args['texts'] or '' | ||
local links = args['links'] or '' | |||
-- divide input here | |||
local imageList = mw.text.split(images, ',') | local imageList = mw.text.split(images, ',') | ||
local textList = mw.text.split(texts, ',') | local textList = mw.text.split(texts, ',') | ||
local linkList = mw.text.split(links, ',') | |||
local html = mw.html.create('div'):addClass('image-grid-container') | local html = mw.html.create('div'):addClass('image-grid-container') | ||
for i = 1, math.max(#imageList, #textList) do | for i = 1, math.max(#imageList, #textList, #linkList) do | ||
local image = mw.text.trim(imageList[i] or 'Noimg.png') | local image = mw.text.trim(imageList[i] or 'Noimg.png') -- default, noimg.png | ||
local text = mw.text.trim(textList[i] or '') | local text = mw.text.trim(textList[i] or '') -- default, empty text | ||
local link = mw.text.trim(linkList[i] or '') -- default, empty link | |||
local imageWrapper = html:tag('div'):addClass('image-wrapper') | local imageWrapper = html:tag('div'):addClass('image-wrapper') | ||
imageWrapper:wikitext(string.format('[[File:%s|200px]]', image)) | if link ~= '' then | ||
imageWrapper:wikitext(string.format('[[%s|File:%s|200px]]', link, image)) | |||
if text ~= '' then | if text ~= '' then | ||
imageWrapper:wikitext(string.format('[[%s|%s]]', link, text)) | |||
end | |||
else | |||
imageWrapper:wikitext(string.format('[[File:%s|200px]]', image)) | |||
if text ~= '' then | |||
imageWrapper:tag('div'):addClass('image-text'):wikitext(text) | |||
end | |||
end | end | ||
end | end |
Revision as of 02:40, 17 September 2024
Documentation for this module may be created at Module:ImageGrid/doc
local p = {}
function p.renderImageGrid(frame)
local args = frame:getParent().args
local images = args['images'] or ''
local texts = args['texts'] or ''
local links = args['links'] or ''
-- divide input here
local imageList = mw.text.split(images, ',')
local textList = mw.text.split(texts, ',')
local linkList = mw.text.split(links, ',')
local html = mw.html.create('div'):addClass('image-grid-container')
for i = 1, math.max(#imageList, #textList, #linkList) do
local image = mw.text.trim(imageList[i] or 'Noimg.png') -- default, noimg.png
local text = mw.text.trim(textList[i] or '') -- default, empty text
local link = mw.text.trim(linkList[i] or '') -- default, empty link
local imageWrapper = html:tag('div'):addClass('image-wrapper')
if link ~= '' then
imageWrapper:wikitext(string.format('[[%s|File:%s|200px]]', link, image))
if text ~= '' then
imageWrapper:wikitext(string.format('[[%s|%s]]', link, text))
end
else
imageWrapper:wikitext(string.format('[[File:%s|200px]]', image))
if text ~= '' then
imageWrapper:tag('div'):addClass('image-text'):wikitext(text)
end
end
end
return tostring(html)
end
return p