Difference between revisions of "Module:Preview warning"

From blackwiki
Jump to navigation Jump to search
blackwiki>Jc86035
m
m (4 revisions imported)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
 +
--[[
 +
main
 +
 +
This function returns parameter 1 as a warning if the page containing it is being previewed.
 +
 +
Usage:
 +
{{#invoke:Preview warning|main|warning_text}}
 +
 +
]]
  
 
function p.main(frame)
 
function p.main(frame)
 
local preview = frame.args[1]:match('^%s*(.-)%s*$') or ''
 
local preview = frame.args[1]:match('^%s*(.-)%s*$') or ''
 
if preview == '' then preview = 'Something is wrong with this template' end
 
if preview == '' then preview = 'Something is wrong with this template' end
if frame:preprocess( "{{REVISIONID}}" ) == "" then return '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview).</div>' end
+
if frame:preprocess( "{{REVISIONID}}" ) == "" then return '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview)</div>' end
 
end
 
end
  
 
return p
 
return p

Latest revision as of 08:25, 27 September 2020

Usage

Put this code in your template. The message will only show in Show preview (you can try with this page):

  • {{#invoke:Preview warning|main|Message text}}



local p = {}

--[[
main

This function returns parameter 1 as a warning if the page containing it is being previewed.

Usage:
{{#invoke:Preview warning|main|warning_text}}

]]

function p.main(frame)
	local preview = frame.args[1]:match('^%s*(.-)%s*$') or ''
	if preview == '' then preview = 'Something is wrong with this template' end
	if frame:preprocess( "{{REVISIONID}}" ) == "" then return '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview)</div>' end
end

return p