Modul:If preview
Tampilan
![]() | Modul ini dilindungi. Modul ini sangat mencolok yang digunakan oleh banyak halaman, atau sangat sering disubstitusikan. Karena vandalisme atau kesalahan akan mempengaruhi banyak halaman, dan suntingan kecil dapat memberi beban besar pada server, modul ini dilindungi dari penyuntingan. |
![]() | Modul ini menggunakan Lua: |
![]() | Modul Lua ini digunakan pada banyak halaman dan perubahannya kemungkinan memicu perubahan massal pada semua halaman yang menggunakannya. Uji cobalah di subhalaman /bak pasir atau /kasus uji Modul:If preview, atau bak pasir modul Anda. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya. |
![]() | Modul ini menggunakan TemplateStyles: |
Modul ini mengimplementasikan {{if preview}} dan {{preview warning}}. Ini membantu templat/modul menentukan apakah templat tersebut sedang dipratinjau.
Untuk menggunakan main()
, Anda harus menggunakan tabel bingkai dengan tabel args.
Untuk peringatan pratinjau, gunakan _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)
return p.main(frame:getParent())
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