Module:ExternalCatalogueLinks: Difference between revisions

From The Seven Sages of Rome
Created page with "-- 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 title = row["Has Ex..."
 
No edit summary
Line 12: Line 12:
      
      
     if not results or #results == 0 then
     if not results or #results == 0 then
         return ""
         return "DEBUG: no results for pagename=" .. pagename
     end
     end
      
      
Line 21: Line 21:
         local link = row["Has External Catalogue Link"]
         local link = row["Has External Catalogue Link"]
          
          
         if title and link then
         -- DEBUG: dump the raw row
             table.insert(items, "[" .. link .. " " .. title .. "]")
        local debug = "ROW: "
        elseif title then
        for k, v in pairs(row) do
            table.insert(items, title)
             debug = debug .. "[" .. tostring(k) .. "=" .. tostring(v) .. "] "
         end
         end
        table.insert(items, debug)
     end
     end
      
      
     return table.concat(items, ", ")
     return table.concat(items, "<br>")
end
end


return p
return p

Revision as of 13:43, 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 "DEBUG: no results for pagename=" .. pagename
    end
    
    local items = {}
    
    for _, row in ipairs(results) do
        local title = row["Has External Catalogue Title"]
        local link = row["Has External Catalogue Link"]
        
        -- DEBUG: dump the raw row
        local debug = "ROW: "
        for k, v in pairs(row) do
            debug = debug .. "[" .. tostring(k) .. "=" .. tostring(v) .. "] "
        end
        table.insert(items, debug)
    end
    
    return table.concat(items, "<br>")
end

return p