Differenze tra le versioni di "Modulo:GetTagFromCategory"

Da Wiki Acquisti in rete PA.
m
m
Riga 6: Riga 6:


   -- Genera i codici di categoria e tag
   -- Genera i codici di categoria e tag
  local renderedTags = {}
   for _, category in ipairs(categories) do
   for _, category in ipairs(categories) do
     category = mw.text.trim(category)
     category = mw.text.trim(category)
Riga 11: Riga 12:
      
      
     -- Assegna il codice dell'oggetto tag corrispondente alla categoria
     -- Assegna il codice dell'oggetto tag corrispondente alla categoria
     if category == "PA" then
     if category == "PA" and not renderedTags["TagPA"] then
       tagCode = tagCode .. frame:expandTemplate{ title = 'TagPA' }
       tagCode = tagCode .. frame:expandTemplate{ title = 'TagPA' }
     elseif category == "AltriBandi" then
      renderedTags["TagPA"] = true
     elseif category == "AltriBandi" and not renderedTags["TagAltriBandi"] then
       tagCode = tagCode .. frame:expandTemplate{ title = 'TagAltriBandi' }
       tagCode = tagCode .. frame:expandTemplate{ title = 'TagAltriBandi' }
     elseif category == "Mepa" then
      renderedTags["TagAltriBandi"] = true
     elseif category == "Mepa" and not renderedTags["TagMepa"] then
       tagCode = tagCode .. frame:expandTemplate{ title = 'TagMepa' }
       tagCode = tagCode .. frame:expandTemplate{ title = 'TagMepa' }
      renderedTags["TagMepa"] = true
     end
     end
   end
   end
Riga 25: Riga 29:
     :wikitext('<div class="tagbox-tags-column"><div class="tagbox-tags-body"><span class="tagbox-label">I tag di questa pagina:</span>' .. tagCode .. '</div></div>')
     :wikitext('<div class="tagbox-tags-column"><div class="tagbox-tags-body"><span class="tagbox-label">I tag di questa pagina:</span>' .. tagCode .. '</div></div>')


   return tagCode .. tostring(html)
   return tostring(html)
end
end


return p
return p

Versione delle 18:16, 1 giu 2023

La documentazione per questo modulo può essere creata in Modulo:GetTagFromCategory/man

local p = {}

function p.generateTagCode(frame)
  local categories = mw.text.split(frame.args[1], ",")
  local tagCode = ""

  -- Genera i codici di categoria e tag
  local renderedTags = {}
  for _, category in ipairs(categories) do
    category = mw.text.trim(category)
    tagCode = tagCode .. "[[Category:" .. category .. "]]"
    
    -- Assegna il codice dell'oggetto tag corrispondente alla categoria
    if category == "PA" and not renderedTags["TagPA"] then
      tagCode = tagCode .. frame:expandTemplate{ title = 'TagPA' }
      renderedTags["TagPA"] = true
    elseif category == "AltriBandi" and not renderedTags["TagAltriBandi"] then
      tagCode = tagCode .. frame:expandTemplate{ title = 'TagAltriBandi' }
      renderedTags["TagAltriBandi"] = true
    elseif category == "Mepa" and not renderedTags["TagMepa"] then
      tagCode = tagCode .. frame:expandTemplate{ title = 'TagMepa' }
      renderedTags["TagMepa"] = true
    end
  end

  -- Genera il codice HTML con i tag
  local html = mw.html.create('div')
    :addClass('tagbox')
    :wikitext('<div class="tagbox-tags-column"><div class="tagbox-tags-body"><span class="tagbox-label">I tag di questa pagina:</span>' .. tagCode .. '</div></div>')

  return tostring(html)
end

return p