it is very disappointing, and IMO should be considered a bug, that templatedata does not support scribunto. there should be an established scribunto library that let me consume "templatedata" of a given template from my lua module (return nil or empty table if template does not exist or does not have TD).
scribunto is used mainly with templates, and the ability to consume templatedata should be considered elementary. User:Anomie explains that it is in the responsibility of each extension to generate the linkage library. see phab:T107119 - open since 2015.
currently, we plug this deficiency by executing the following abomination ("docSubPage" is predefined, to the "ducumentation" convention name of the specific wiki):
local function _readTemplateData( templateName )
local title = mw.title.makeTitle( 0, templateName )
local templateContent = title and title.exists and title:getContent() ''-- template's raw content''
local capture = templateContent and mw.ustring.match( templateContent, '<templatedata%s*>(.*)</templatedata%s*>' ) ''-- templatedata as text''
''-- capture = capture and mw.ustring.gsub( capture, '"(%d+)"', tonumber ) -- convert "1": {} to 1: {}. frame.args uses numerical indexes for order-based params.''
if capture then return pcall( mw.text.jsonDecode, capture ) end
return false
end
local function readTemplateData( templateName )
if type( templateName ) == 'string' then
templateName = { templateName, templateName .. '/' .. docSubPage }
end
if type( templateName ) == "table" then
for _, name in ipairs( templateName ) do
local td, result = _readTemplateData( name )
if td then return result end
end
end
return nil
end
please follow the instructions (here), and be done with it.
peace.