Module:Blocks: Difference between revisions
Appearance
Content deleted Content added
fixing transclusion code |
accept contentN parameter |
||
Line 6: | Line 6: | ||
local index = 1 |
local index = 1 |
||
while parent.args['page' .. index] do |
while parent.args['page' .. index] or parent.args['content' .. index] do |
||
local pageName = parent.args['page' .. index] |
local pageName = parent.args['page' .. index] |
||
local content = parent.args['content' .. index] |
|||
local sectionName = parent.args['section' .. index] |
local sectionName = parent.args['section' .. index] |
||
local pageDiv = mw.html.create('div'):addClass('blocks-block') |
local pageDiv = mw.html.create('div'):addClass('blocks-block') |
||
Line 15: | Line 16: | ||
end |
end |
||
local transcludedContent = frame:expandTemplate{title = pageName} |
if pageName then |
||
local transcludedContent = frame:expandTemplate{title = pageName} |
|||
pageDiv:wikitext('\n' .. transcludedContent) |
pageDiv:wikitext('\n' .. transcludedContent) |
||
elseif content then |
|||
pageDiv:wikitext('\n' .. content) |
|||
end |
|||
table.insert(pages, pageDiv) |
table.insert(pages, pageDiv) |
||
index = index + 1 |
index = index + 1 |
Revision as of 00:01, 7 May 2023
This module is used for Template:Blocks.
Usage
To use this module, add the following code to your wiki page:
{{#invoke:Blocks|main}}
Inputs
See Template:Blocks/doc#Usage.
Outputs
This module outputs a single string containing the HTML markup for the generated blocks. Each block will include:
- The section name (if provided) as an
<h2>
heading, followed by an edit link (either to that page or the transcluded page if a page title is passed). - The transcluded content from the specified page or the provided content, wrapped in a
<div>
with the classblocks-block
.
local p = {}
function p.main(frame)
local parent = frame:getParent()
local pages = {}
local index = 1
while parent.args['page' .. index] or parent.args['content' .. index] do
local pageName = parent.args['page' .. index]
local content = parent.args['content' .. index]
local sectionName = parent.args['section' .. index]
local pageDiv = mw.html.create('div'):addClass('blocks-block')
if sectionName then
pageDiv:wikitext('\n==' .. sectionName .. '==')
end
if pageName then
local transcludedContent = frame:expandTemplate{title = pageName}
pageDiv:wikitext('\n' .. transcludedContent)
elseif content then
pageDiv:wikitext('\n' .. content)
end
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