Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 225: Line 225:
if hasDocuments then
if hasDocuments then
-- Use #ask with array format
-- 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=array\n' ..
' |format=broadtable\n' ..
' |propsep=§\n' ..
' |headers=hide\n' ..
' |sep=¶\n' ..
' |link=none\n' ..
' |link=none\n' ..
' |headers=hide\n' ..
'}}'
'}}'
local docsResult = frame:preprocess(docsQueryWikitext)
local docsResult = frame:preprocess(docsQueryWikitext)
-- DEBUG: Show raw result
local debugDiv = mw.html.create('div')
debugDiv:css('background', '#fee'):css('padding', '5px'):css('margin', '5px 0')
debugDiv:wikitext('DEBUG docsResult: <pre>' .. mw.text.encode(docsResult or 'nil') .. '</pre>')
td:node(debugDiv)
-- 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')
-- Add a test item to verify UL works
-- Parse the HTML table - extract data from <td> tags
local testLi = ul:tag('li')
-- Pattern: <td ...>page</td><td ...>type</td><td ...>URL</td>
testLi:wikitext('[https://example.com Test Link]')
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)
MediaWiki Appliance - Powered by TurnKey Linux