Differenze tra le versioni di "Modulo:GetTagFromCategory"

Da Wiki Acquisti in rete PA.
m
m
Riga 1: Riga 1:
local p = {}
local p = {}


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


   -- Verifica se ci sono categorie
   -- Genera i codici di categoria
   if categories then
   for _, category in ipairs(categories) do
    -- Controlla ogni categoria e aggiungi l'oggetto tag corrispondente
    category = mw.text.trim(category)
    for _, category in ipairs(categories) do
    tagCode = tagCode .. "[[Category:" .. category .. "]]"
      -- Rimuovi il prefisso "Categoria:"
      category = category:gsub("^Categoria:", "")
     
      -- Aggiungi l'oggetto tag corrispondente in base alla categoria trovata
      if category == "PA" then
        tags = tags .. frame:expandTemplate{ title = 'TagPA' }
      elseif category == "AltriBandi" then
        tags = tags .. frame:expandTemplate{ title = 'TagAltriBandi' }
      end
      -- Aggiungi altre condizioni if-elseif per categorie aggiuntive e relativi oggetti tag
      -- ad esempio: elseif category == "CategoriaX" then tags = tags .. frame:expandTemplate{ title = 'TagX' }
    end
  else
    -- Se non ci sono categorie, restituisci una stringa vuota per nascondere il blocco
    return ""
   end
   end


Riga 29: Riga 14:
   local html = mw.html.create('div')
   local html = mw.html.create('div')
     :addClass('tagbox')
     :addClass('tagbox')
     :wikitext('<div class="tagbox-tags-column"><div class="tagbox-tags-body"><span class="tagbox-label">I tag di questa pagina:</span>' .. tags .. '</div></div>')
     :wikitext('<div class="tagbox-tags-column"><div class="tagbox-tags-body"><span class="tagbox-label">I tag di questa pagina:</span>' .. frame:expandTemplate{ title = 'Categoria1' } .. frame:expandTemplate{ title = 'Categoria2' } .. frame:expandTemplate{ title = 'Categoria3' } .. '</div></div>')


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


return p
return p

Versione delle 17:51, 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
  for _, category in ipairs(categories) do
    category = mw.text.trim(category)
    tagCode = tagCode .. "[[Category:" .. category .. "]]"
  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>' .. frame:expandTemplate{ title = 'Categoria1' } .. frame:expandTemplate{ title = 'Categoria2' } .. frame:expandTemplate{ title = 'Categoria3' } .. '</div></div>')

  return tagCode .. tostring(html)
end

return p