Documentation for this module may be created at Module:CategoryTranscluder/doc
local p = {}
-- Function to retrieve and transclude pages in a given category
function p.transcludeCategory(frame)
-- Get the category name from the arguments
local args = frame:getParent().args
local categoryName = args[1]
if not categoryName or categoryName == "" then
return "Error: No category specified."
end
-- Initialize a buffer to hold the transcluded content
local contentBuffer = {}
-- Iterate through pages in the category
local category = mw.site.getCategory(categoryName)
if not category then
return "Error: Category not found."
end
local count = 0
for _, page in ipairs(category:members()) do
count = count + 1
-- Only transclude articles, not files or subcategories
if page.ns == 0 then
table.insert(contentBuffer, string.format("<includeonly>{{:%s}}</includeonly>", page.text))
end
-- Optional: Stop after a set limit to prevent excessive processing
if count > 100 then
table.insert(contentBuffer, "<!-- Output truncated to the first 100 items. -->")
break
end
end
-- Combine the transcluded content and return it
return table.concat(contentBuffer, "\n")
end
return p