Jump to content

Module:Blocks: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
module for rendering stylized blocks for content
 
accept section parameter
Line 8: Line 8:
while parent.args['page' .. index] do
while parent.args['page' .. index] do
local pageName = parent.args['page' .. index]
local pageName = parent.args['page' .. index]
local sectionName = parent.args['section' .. index]
table.insert(pages, mw.html.create('div')
:addClass('blocks-block')
local pageDiv = mw.html.create('div'):addClass('blocks-block')

:wikitext('{{' .. pageName .. '}}')
)
if sectionName then
pageDiv:wikitext('==' .. sectionName .. '==')
end

pageDiv:wikitext('{{' .. pageName .. '}}')
table.insert(pages, pageDiv)
index = index + 1
index = index + 1
end
end

Revision as of 23:37, 28 April 2023

local p = {}

function p.main(frame)
    local parent = frame:getParent()
    local pages = {}
    local index = 1

    while parent.args['page' .. index] do
        local pageName = parent.args['page' .. index]
        local sectionName = parent.args['section' .. index]
        local pageDiv = mw.html.create('div'):addClass('blocks-block')

        if sectionName then
            pageDiv:wikitext('==' .. sectionName .. '==')
        end

        pageDiv:wikitext('{{' .. pageName .. '}}')
        table.insert(pages, pageDiv)
        index = index + 1
    end

    if #pages == 0 then
        return ''
    end

    local mainDiv = mw.html.create('div')
    for _, pageDiv in ipairs(pages) do
        mainDiv:node(pageDiv)
    end

    return tostring(mainDiv)
end

return p