Module:ExternalCatalogueLinks: Difference between revisions

From The Seven Sages of Rome
No edit summary
No edit summary
Line 17: Line 17:
     local items = {}
     local items = {}
      
      
    for _, row in ipairs(results) do
for _, row in ipairs(results) do
        local title = row[1]
    local debug = "ROW: "
        local link = row["Has External Catalogue Link"]
    for k, v in pairs(row) do
       
         debug = debug .. "[key=" .. tostring(k) .. " type=" .. type(k) .. " val=" .. tostring(v) .. "] "
         if title and link then
            table.insert(items, "[" .. link .. " " .. title .. "]")
        elseif title then
            table.insert(items, title)
        end
     end
     end
    table.insert(items, debug)
end
      
      
     return table.concat(items, ", ")
     return table.concat(items, ", ")

Revision as of 13:45, 26 February 2026

Documentation for this module may be created at Module:ExternalCatalogueLinks/doc

-- Module:ExternalCatalogueLinks
local p = {}

function p.render(frame)
    local pagename = frame:preprocess("{{PAGENAME}}")
    
    local results = mw.smw.ask({
        "[[- Has subobject::" .. pagename .. "]]",
        "?Has External Catalogue Title",
        "?Has External Catalogue Link"
    })
    
    if not results or #results == 0 then
        return ""
    end
    
    local items = {}
    
for _, row in ipairs(results) do
    local debug = "ROW: "
    for k, v in pairs(row) do
        debug = debug .. "[key=" .. tostring(k) .. " type=" .. type(k) .. " val=" .. tostring(v) .. "] "
    end
    table.insert(items, debug)
end
    
    return table.concat(items, ", ")
end

return p