Module:RecursiveSelectiveList: Difference between revisions

From Ikwipedia
No edit summary
No edit summary
Line 3: Line 3:


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args or {}
    -- Retrieve parameters from the template invocation
   
     local args = frame.args
    -- Normalize parameter name case (if there's a case mismatch)
     local pageName = args.pageName
     local pageName = args["pageName"] or args["PageName"] or args["pagename"]


     -- Check if pageName is missing or empty
     -- Check if 'pageName' is provided
     if not pageName or pageName == "" then
     if not pageName or pageName == "" then
         return "Error: 'pageName' parameter is missing or empty."
         return "Error: 'pageName' parameter is missing or empty."
     end
     end


     -- Fetch page content
     -- Fetch content for the specified page
     local pageContent = mw.title.new(pageName):getContent()
     local pageContent = mw.title.new(pageName):getContent()


    -- Handle cases where the page doesn't exist or has no content
     if not pageContent then
     if not pageContent then
         return "Error: The page '" .. pageName .. "' does not exist or has no content."
         return "Error: The page '" .. pageName .. "' does not exist or has no content."

Revision as of 07:14, 22 December 2024

Documentation for this module may be created at Module:RecursiveSelectiveList/doc

local p = {}
local mw = require('mw')

function p.main(frame)
    -- Retrieve parameters from the template invocation
    local args = frame.args
    local pageName = args.pageName

    -- Check if 'pageName' is provided
    if not pageName or pageName == "" then
        return "Error: 'pageName' parameter is missing or empty."
    end

    -- Fetch content for the specified page
    local pageContent = mw.title.new(pageName):getContent()

    -- Handle cases where the page doesn't exist or has no content
    if not pageContent then
        return "Error: The page '" .. pageName .. "' does not exist or has no content."
    end

    return pageContent
end

return p