Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:ImageGrid: Difference between revisions

From MassiveCraft Wiki
Created page with "local p = {} function p.renderImageGrid(frame) local args = frame:getParent().args local images = mw.text.split(args['images'], ',') local texts = mw.text.split(args['texts'], ',') local imageCount = #images local html = mw.html.create('div'):addClass('image-grid-container') for i = 1, imageCount do local imageWrapper = html:tag('div'):addClass('image-wrapper') local imageTag = imageWrapper:tag('img') :attr('src', ima..."
 
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 = mw.text.split(args['images'], ',')
     local images = args['images'] or ''
     local texts = mw.text.split(args['texts'], ',')
    local texts = args['texts'] or ''
    local imageCount = #images
 
    local imageList = mw.text.split(images, ',')
     local textList = mw.text.split(texts, ',')
 
     local html = mw.html.create('div'):addClass('image-grid-container')
     local html = mw.html.create('div'):addClass('image-grid-container')


     for i = 1, imageCount do
     for i = 1, math.max(#imageList, #textList) do
        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
 
         local imageWrapper = html:tag('div'):addClass('image-wrapper')
         local imageWrapper = html:tag('div'):addClass('image-wrapper')
         local imageTag = imageWrapper:tag('img')
 
            :attr('src', images[i])
         imageWrapper:wikitext(string.format('[[File:%s|200px]]', image))
            :attr('alt', texts[i] or '')
 
         local textTag = imageWrapper:tag('div'):addClass('image-text'):wikitext(texts[i] or '')
         if text ~= '' then
            imageWrapper:tag('div'):addClass('image-text'):wikitext(text)
        end
     end
     end



Revision as of 02:36, 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 imageList = mw.text.split(images, ',')
    local textList = mw.text.split(texts, ',')

    local html = mw.html.create('div'):addClass('image-grid-container')

    for i = 1, math.max(#imageList, #textList) do
        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

        local imageWrapper = html:tag('div'):addClass('image-wrapper')

        imageWrapper:wikitext(string.format('[[File:%s|200px]]', image))

        if text ~= '' then
            imageWrapper:tag('div'):addClass('image-text'):wikitext(text)
        end
    end

    return tostring(html)
end

return p