Module:Ifexist and Module:Ifexist/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
imported>Codemini
m I think the removal of mw.title.new caused a false statement when invoked onto a page
 
imported>Raph Williams65
A space for experimental module code for Module:Ifexist
 
Line 1: Line 1:
-- This module implements {{If-exist}}
--[[
-- optional if template {{If}} seems difficult to use
    Add your expirimental module code here
local p = {}
--]]
local p = {} -- represents p as a code for packages


function p.main(frame)
function p.main(frame) -- package name = main, (frame) = global frame
  title = frame.args[1] or '' -- PAGENAME
  title = frame.args[1] -- parameter 1
  thenthis = frame.args[2] --THEN RETURN THIS
  thenthis = frame.args[2] -- parameter 2
  elsethis = frame.args[3] --ELSE THIS
  elsethis = frame.args[3] -- parameter 3
--[[
    If this then return this else return this
--]]
  if mw.title.new(title).exists == true then
  if mw.title.new(title).exists == true then
  return thenthis
return thenthis
else
  else
  return elsethis
  return elsethis
-- if title exists then return this, if title doesn't exist then this
  end
if not title then
  return error('Error at [[Template:If-exist]]: No page title found')
  end
  end
--[[
    You can use the magic word ({{#ifexist:title|thenthis|elsethis}})
--]]
end
end
return p
return p