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 to get raw values | ||
local | local docsQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[Category:Documents]]\n' .. | ' [[Category:Documents]]\n' .. | ||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ||
' | | ' |?Has document type\n' .. | ||
' |?Has document URL\n' .. | |||
' |format=array\n' .. | |||
' |propsep=@@\n' .. | |||
' |valuesep=##\n' .. | |||
' |sep=|||\n' .. | |||
' |link=none\n' .. | ' |link=none\n' .. | ||
'}}' | '}}' | ||
local | local docsResult = frame:preprocess(docsQueryWikitext) | ||
-- | -- Parse the array format: each document separated by |||, properties by @@ | ||
if | if docsResult and trim(docsResult) then | ||
for | for docData in docsResult:gmatch('[^|]+') do | ||
-- Split by @@ to get page name, type, and URL | |||
local parts = {} | |||
for part in (docData .. '@@'):gmatch('([^@]*)@@') do | |||
table.insert(parts, trim(part)) | |||
local | end | ||
-- parts[1] = page name, parts[2] = document type, parts[3] = URL | |||
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 | ||