Module

TemplateSource

From Dogcraft Wiki

mNo edit summary
mNo edit summary
Line 3: Line 3:
function p.test(frame)
function p.test(frame)
source = frame:expandTemplate{ title = 'Templates Nav', args = {} }
source = frame:expandTemplate{ title = 'Templates Nav', args = {} }
return frame:preprocess('{{Templates Nav}}')
return mw.ustring.len( source )
end
end


return p
return p

Revision as of 19:10, 31 January 2026

Meant to be used with the {{Template source}} template. Returns the plaintext contents of a template. Obeys the mostly the same behaviours as transclusion would, respects <onlyinclude>, <includeonly>, and <noinclude> tags. This module is primarily meant to be used as input to <syntaxhighlight>, which doesn't handle some tags (like <templatestyles> or <categorytree>) correctly.

Example

The source of the {{Pagetabs}} template, wrapped in a <syntaxhighlight> tag.

{{#tag:syntaxhighlight|{{#invoke:TemplateSource|templateSource|Template:Pagetabs}}|lang=html|line=1}} generates:

<strong class="error"><span class="scribunto-error" id="mw-scribunto-error-0">Script error: The function &quot;templateSource&quot; does not exist.</span></strong>

local p = {}

function p.test(frame)
	source = frame:expandTemplate{ title = 'Templates Nav', args = {} }
	return mw.ustring.len( source )
end

return p
This page was last modified on 31 January 2026, at 19:10. (2 days ago)