模块:TemplateDemo:修订间差异

来自「荏苒之境」
无编辑摘要
无编辑摘要
第1行: 第1行:
local html = mw.html
local template_demo = {}
local template_demo = {}


template_demo.show = function(frame)
template_demo.show = function(frame)
local view = mw.html.create("ul")
local args = frame.args
local template_name = args[1]
 
if template_name == nil or template_name == '' then
return html.create("p"):addClass("error")
:wikitext("没有指定模板名!")
end
local t = {"{{", template_name, "\n"}
for k, v in pairs(frame:getParent().args) do
for k, v in pairs(frame:getParent().args) do
view:tag("li"):wikitext(k..": "..v)
t[#t+1] = "| "
t[#t+1] = k
t[#t+1] = " = "
t[#t+1] = v
t[#t+1] = "\n"
end
end
return view
t[#t+1] = "}}"
local source = table.concat(t)
local result = frame:preprocess(source)
return result.."示例:\n<pre>"..source.."\n</pre>"
end
end


return template_demo
return template_demo

2025年8月7日 (四) 19:32的版本

此模块的文档可以在模块:TemplateDemo/doc创建

local html = mw.html

local template_demo = {}

template_demo.show = function(frame)
	local args = frame.args
	local template_name = args[1]

	if template_name == nil or template_name == '' then
		return html.create("p"):addClass("error")
			:wikitext("没有指定模板名!")
	end
	
	local t = {"{{", template_name, "\n"}
	for k, v in pairs(frame:getParent().args) do
		t[#t+1] = "| "
		t[#t+1] = k
		t[#t+1] = " = "
		t[#t+1] = v
		t[#t+1] = "\n"
	end
	t[#t+1] = "}}"
	
	local source = table.concat(t)
	local result = frame:preprocess(source)
	
	return result.."示例:\n<pre>"..source.."\n</pre>"
end

return template_demo