A Wiki in the Desert
Log in

Difference between revisions of "Module:HerbGallery"

From A Wiki in the Desert
Line 10: Line 10:
 
     end
 
     end
 
      
 
      
     local queryResult = mw.smw.ask( frame:getParent().args )
+
     local queryResult = mw.smw.getQueryResult( frame:getParent().args[1] )
  
 
     if queryResult == nil then
 
     if queryResult == nil then
Line 16: Line 16:
 
     end
 
     end
  
 +
    local currentIndex = 1
 +
    local galleryArgs = {
 +
    width="200",
 +
    height="200",
 +
    mode="packed"
 +
    }
 +
   
 
     if type( queryResult ) == "table" then
 
     if type( queryResult ) == "table" then
 
         local myResult = ""
 
         local myResult = ""
         for num, row in pairs( queryResult ) do
+
         for k,v in pairs( queryResult.results ) do
             for property, data in pairs( row ) do
+
             for kR,vR in pairs( v.printouts.image ) do
                local dataOutput = data
+
            galleryArgs[currentIndex] = vR.fulltext
                if type( data ) == 'table' then
+
            currentIndex = currentIndex + 1
                    dataOutput = mw.text.listToText( data, ', ', ' and ')
 
                end
 
                myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
 
 
             end
 
             end
 
         end
 
         end
         return myResult
+
         return frame:expandTemplate{ title = 'Gallery', args = galleryArgs }
 
     end
 
     end
  
     return queryResult
+
     return ""
 
end
 
end
  
 
return p
 
return p

Revision as of 03:24, 15 May 2021

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

local p = {} --p stands for package

function p.gallery( frame )
	if not mw.smw then
        return "mw.smw module not found"
	end

    if frame:getParent().args[1] == nil then
        return "no parameter found"
    end
    
    local queryResult = mw.smw.getQueryResult( frame:getParent().args[1] )

    if queryResult == nil then
        return "(no values)"
    end

    local currentIndex = 1
    local galleryArgs = {
    	width="200", 
    	height="200", 
    	mode="packed"
    }
    
    if type( queryResult ) == "table" then
        local myResult = ""
        for k,v in pairs( queryResult.results ) do
            for kR,vR in pairs( v.printouts.image ) do
            	galleryArgs[currentIndex] = vR.fulltext
            	currentIndex = currentIndex + 1
            end
        end
        return frame:expandTemplate{ title = 'Gallery', args = galleryArgs }
    end

    return ""
end

return p