Module:ExternalCatalogueLinks: Difference between revisions

From The Seven Sages of Rome
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 12: Line 12:
      
      
     if not results or #results == 0 then
     if not results or #results == 0 then
         return "DEBUG: no results for pagename=" .. pagename
         return ""
     end
     end
      
      
     local items = {}
     local items = {}
      
      
    for _, row in ipairs(results) do
for _, row in ipairs(results) do
        local title = row["Has External Catalogue Title"]
    local link = row["Has External Catalogue Link"]
        local link = row["Has External Catalogue Link"]
    local title = row["Has External Catalogue Title"]
       
   
        -- DEBUG: dump the raw row
    if link then
        local debug = "ROW: "
        if title then
        for k, v in pairs(row) do
            table.insert(items, "[" .. link .. " " .. title .. "]")
            debug = debug .. "[" .. tostring(k) .. "=" .. tostring(v) .. "] "
        else
        end
            table.insert(items, "[" .. link .. "]")
        table.insert(items, debug)
        end
    end
    end
end
      
      
     return table.concat(items, "<br>")
     return table.concat(items, ", ")
end
end


return p
return p

Latest revision as of 13:47, 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 link = row["Has External Catalogue Link"]
    	local title = row["Has External Catalogue Title"]
    
    	if link then
        	if title then
            	table.insert(items, "[" .. link .. " " .. title .. "]")
        	else
            	table.insert(items, "[" .. link .. "]")
        	end
    	end
	end
    
    return table.concat(items, ", ")
end

return p