Module:Ifexists

From Fallen London Wiki

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

local p = {}
 
function p.exists(frame)
    local sText = frame.args[1]
    local sTrueAction = frame.args[2]
    local sFalseAction = frame.args[3]
    if (sText) then 
        if mw.title.new(sText).exists then
            return sTrueAction
        else 
            return sFalseAction
        end
    end
end
 
function p.hasContent(frame)
    local sText = frame.args[1]
    local sTrueAction = frame.args[2]
    local sFalseAction = frame.args[3]
    if (sText) then
        local page = mw.title.new(sText)
        if page.exists and not require('Module:Redirect').isRedirect(page) then
            return sTrueAction
        else
            return sFalseAction
        end
    end
end

return p
-- Use:
-- {{#invoke:ifexists|exists|<pagename>|true|false}}
-- {{#invoke:ifexists|hasContent|<pagename>|true|false}}
-- hasContent returns true if the page exists and is not a redirect page