Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 154: Line 154:
     feature = 'countryWrapper',
     feature = 'countryWrapper',
     render  = function(template, args) -- Added template, args
     render  = function(template, args) -- Added template, args
         local normalizedCountryName = args.has_country -- From preprocessor
         -- local normalizedCountryName = args.has_country -- From preprocessor
         local flagImageWikitext = ""
         -- local flagImageWikitext = ""


         if normalizedCountryName and normalizedCountryName ~= "" then
         -- if normalizedCountryName and normalizedCountryName ~= "" then
            local isoCode = CountryData.getCountryCodeByName(normalizedCountryName)
        --    local isoCode = CountryData.getCountryCodeByName(normalizedCountryName)
            if isoCode and #isoCode == 2 then
        --    if isoCode and #isoCode == 2 then
                local flagFile = "Flag-" .. string.lower(isoCode) .. ".svg"
        --        local flagFile = "Flag-" .. string.lower(isoCode) .. ".svg"
                -- Using a new class 'country-wrapper-bg-image' for the image
        --        -- Using a new class 'country-wrapper-bg-image' for the image
                flagImageWikitext = string.format(
        --        flagImageWikitext = string.format(
                    "[[File:%s|link=|class=country-wrapper-bg-image]]",  
        --            "[[File:%s|link=|class=country-wrapper-bg-image]]",  
                    flagFile
        --            flagFile
                )
        --        )
            end
        --    end
         end
         -- end
          
          
         return '<div class="country-hub-wrapper">' .. flagImageWikitext -- Appended flag
         return '<div class="country-hub-wrapper">' -- .. flagImageWikitext -- Appended flag
     end
     end
}
}
Line 266: Line 266:
         end
         end
          
          
        local flagImageWikitext = ""
        if queryCountryName and queryCountryName ~= "" then
            local isoCode = CountryData.getCountryCodeByName(queryCountryName)
            if isoCode and #isoCode == 2 then
                local flagFile = "Flag-" .. string.lower(isoCode) .. ".svg"
                flagImageWikitext = string.format(
                    "[[File:%s|link=|class=country-infobox-bg-image]]",
                    flagFile
                )
            end
        end
         -- Assemble the HTML for the infobox table
         -- Assemble the HTML for the infobox table
         local infoBox = html.create('table')
         local infoBoxWrapper = html.create('div')
            :addClass('country-hub-infobox-wrapper')
       
        local infoBox = infoBoxWrapper:tag('table')
             :addClass('country-hub-infobox icannwiki-automatic-text')
             :addClass('country-hub-infobox icannwiki-automatic-text')
          
          
Line 305: Line 320:
             :done()
             :done()
          
          
         return tostring(infoBox)
        infoBoxWrapper:wikitext(flagImageWikitext)
       
         return tostring(infoBoxWrapper)
     end
     end
}
}