Module:If preview/sandbox

This is an old revision of this page, as edited by Izno (talk | contribs) at 14:57, 29 April 2021 (continue reducing per YAGNI). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

--[[
main

This function returns the either the first argument or second argument passed to
this module, depending on whether it is being previewed.

Usage:
{{#invoke:If preview|main|value_if_preview|value_if_not_preview}}

]]
function p.main(frame)
	local revision_id = frame:preprocess('{{REVISIONID}}')
	-- {{REVISIONID}} is usually the empty string when previewed.
	if not revision_id == nil and not revision_id == '' then
		return frame.args[1] or ''
	else
		return frame.args[2] or ''
	end
end

return p