Difference between revisions of "Module:If preview"
Jump to navigation
Jump to search
blackwiki>Evad37 (replace is_set with code from Module:Citation/CS1/Utilities. Note previous edit was derived from Module:Citation/CS1/sandbox code.) |
blackwiki>Evad37 (parent.args for pmain, fix boolean function name) |
||
| Line 37: | Line 37: | ||
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id | Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id | ||
if not (Preview_mode == nil or Preview_mode == '') then -- if there is a value then this is not a preiview | if not (Preview_mode == nil or Preview_mode == '') then -- if there is a value then this is not a preiview | ||
| − | result = | + | result = parent.args[2] |
else | else | ||
| − | result = | + | result = parent.args[1]; -- no value (nil or empty string) so this is a preview |
end | end | ||
return result | return result | ||
| Line 54: | Line 54: | ||
]] | ]] | ||
| − | function p. | + | function p.boolean(frame) |
local result = '' | local result = '' | ||
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id | Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id | ||
Revision as of 05:46, 13 May 2016
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
A module to help templates/modules determine if they are being previewed.
- See also: Module:Preview warning
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 result = ''
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id
if not (Preview_mode == nil or Preview_mode == '') then -- if there is a value then this is not a preiview
result = frame.args[2] or '';
else
result = frame.args[1] or ''; -- no value (nil or empty string) so this is a preview
end
return result
end
--[[
pmain
This function returns the either the first argument or second argument passed to this module's parent (i.e. template using this module), depending on whether it is being previewed.
Usage:
{{#invoke:If preview|pmain}}
]]
function p.pmain(frame)
local parent = frame.getParent(frame)
local result = ''
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id
if not (Preview_mode == nil or Preview_mode == '') then -- if there is a value then this is not a preiview
result = parent.args[2]
else
result = parent.args[1]; -- no value (nil or empty string) so this is a preview
end
return result
end
--[[
boolean
This function returns the either true or false, depending on whether it is being previewed.
Usage:
{{#invoke:If preview|boolean}}
]]
function p.boolean(frame)
local result = ''
Preview_mode = frame:preprocess('{{REVISIONID}}'); -- use magic word to get revision id
if not (Preview_mode == nil or Preview_mode == '') then -- if there is a value then this is not a preiview
result = false;
else
result = true; -- no value (nil or empty string) so this is a preview
end
return result
end
return p