Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 229: | Line 229: | ||
ul:css('margin', '0'):css('padding-left', '1.5em') | ul:css('margin', '0'):css('padding-left', '1.5em') | ||
-- Use #ask with array format | -- Use #ask with array format - simpler separators | ||
local docsQueryWikitext = | local docsQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
| Line 237: | Line 237: | ||
' |?Has document URL\n' .. | ' |?Has document URL\n' .. | ||
' |format=array\n' .. | ' |format=array\n' .. | ||
' |propsep= | ' |propsep=§\n' .. | ||
' |sep=¶\n' .. | |||
' |sep= | |||
' |link=none\n' .. | ' |link=none\n' .. | ||
' |headers=hide\n' .. | |||
'}}' | '}}' | ||
local docsResult = frame:preprocess(docsQueryWikitext) | local docsResult = frame:preprocess(docsQueryWikitext) | ||
-- Parse the | -- Parse the result - format should be: PageName§Type§URL¶PageName§Type§URL | ||
if docsResult and trim(docsResult) then | if docsResult and trim(docsResult) then | ||
for | -- Split by paragraph symbol (documents separator) | ||
-- Split by | for docLine in docsResult:gmatch('[^¶]+') do | ||
docLine = trim(docLine) | |||
if docLine and docLine ~= '' then | |||
-- Split by section symbol (properties separator) | |||
local parts = {} | |||
for part in docLine:gmatch('[^§]+') do | |||
table.insert(parts, trim(part)) | |||
end | |||
-- Create list item with link | -- parts[1] = page name, parts[2] = type, parts[3] = URL | ||
if #parts >= 3 then | |||
local docType = parts[2] | |||
local docUrl = parts[3] | |||
if docUrl and docUrl ~= '' then | |||
local displayText = (docType and docType ~= '') and docType or 'Document' | |||
-- Create list item with link | |||
local li = ul:tag('li') | |||
li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']') | |||
end | |||
end | |||
end | end | ||
end | end | ||