Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 225: | Line 225: | ||
if hasDocuments then | if hasDocuments then | ||
-- Use #ask | -- Use #ask - it returns an HTML table | ||
local docsQueryWikitext = | local docsQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
| Line 232: | Line 232: | ||
' |?Has document type\n' .. | ' |?Has document type\n' .. | ||
' |?Has document URL\n' .. | ' |?Has document URL\n' .. | ||
' |format= | ' |format=broadtable\n' .. | ||
' | | ' |headers=hide\n' .. | ||
' |link=none\n' .. | ' |link=none\n' .. | ||
'}}' | '}}' | ||
local docsResult = frame:preprocess(docsQueryWikitext) | local docsResult = frame:preprocess(docsQueryWikitext) | ||
-- Create UL element | -- Create UL element | ||
| Line 250: | Line 242: | ||
ul:css('margin', '0'):css('padding-left', '1.5em') | ul:css('margin', '0'):css('padding-left', '1.5em') | ||
-- | -- Parse the HTML table - extract data from <td> tags | ||
-- Pattern: <td ...>page</td><td ...>type</td><td ...>URL</td> | |||
if docsResult then | |||
-- Match each table row | |||
for rowContent in docsResult:gmatch('<tr[^>]*>(.-)</tr>') do | |||
local cells = {} | |||
-- Extract content from each <td> | |||
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do | |||
-- Strip any remaining HTML tags and get just the text | |||
local cleanContent = cellContent:gsub('<[^>]+>', '') | |||
table.insert(cells, trim(cleanContent)) | |||
end | |||
-- cells[1] = page name, cells[2] = type, cells[3] = URL | |||
if #cells >= 3 then | |||
local docType = cells[2] | |||
local docUrl = cells[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 | |||
td:node(ul) | td:node(ul) | ||