Module:TemplateHelpers: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 493: Line 493:
     -- Handle multi-value fields that need to be split
     -- Handle multi-value fields that need to be split
     if options.multiValueFields then
     if options.multiValueFields then
        -- For non-SMW case, collect property HTML fragments in a table for efficient concatenation
        local propertyHtml = {}
       
         for property, config in pairs(options.multiValueFields) do
         for property, config in pairs(options.multiValueFields) do
             local fieldName = config.field
             local fieldName = config.field
Line 510: Line 513:
                             mw.smw.set({[property] = value})
                             mw.smw.set({[property] = value})
                         else
                         else
                             semanticOutput = semanticOutput .. "\n" ..
                             -- Collect HTML fragments instead of concatenating strings
                                '<div style="display:none;">\n {{#set: ' .. property .. '=' ..  
                            table.insert(propertyHtml, '<div style="display:none;">')
                                value .. ' }}\n</div>'
                            table.insert(propertyHtml, ' {{#set: ' .. property .. '=' .. value .. ' }}')
                            table.insert(propertyHtml, '</div>')
                         end
                         end
                     end
                     end
                 end
                 end
             end
             end
        end
       
        -- For non-SMW case, concatenate all property HTML fragments at once
        if not mw.smw and #propertyHtml > 0 then
            semanticOutput = semanticOutput .. "\n" .. table.concat(propertyHtml, "\n")
         end
         end
     end
     end