Module:T-Campaign: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 183: Line 183:
         end
         end
          
          
         -- WORKAROUND for Scribunto bug: Launder the string and replace directly.
         -- Get the title from the central configuration
 
         local titleText = template.config.constants.title or "Campaign"
        -- 1. Get the raw title value
          
         local rawTitle = args._campaign_data.defaults.title or "Campaign"
         -- Replace placeholder and process links
 
         bannerContent = bannerContent:gsub("%$CAMPAIGN_NAME%$", titleText)
         -- 2. Launder the string to create a clean copy
        local function launderString(inputStr)
            if type(inputStr) ~= 'string' then return tostring(inputStr) end
            local newStr = ""
            for i = 1, #inputStr do
                newStr = newStr .. string.char(string.byte(inputStr, i))
            end
            return newStr
        end
        local cleanTitle = launderString(rawTitle)
 
         -- 3. Directly replace the placeholder in the banner content string
         bannerContent = bannerContent:gsub("%$CAMPAIGN_NAME%$", cleanTitle)
 
        -- 4. Pass the processed content to the WikitextProcessor for link handling only
         bannerContent = WikitextProcessor.processWikiLinksToHTML(bannerContent, context)
         bannerContent = WikitextProcessor.processWikiLinksToHTML(bannerContent, context)
          
          
Line 402: Line 387:
     -- Always show campaign content fields (they'll show placeholder text when empty)
     -- Always show campaign content fields (they'll show placeholder text when empty)
     for _, fieldDef in ipairs(campaignData.field_definitions) do
     for _, fieldDef in ipairs(campaignData.field_definitions) do
         table.insert(fields, {
         -- CRITICAL: Skip 'title' as it is not a content field
            key = fieldDef.key,
        if fieldDef.key ~= "title" then
            label = fieldDef.label,
            table.insert(fields, {
            type = fieldDef.type
                key = fieldDef.key,
        })
                label = fieldDef.label,
                type = fieldDef.type
            })
        end
     end
     end