Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:String: Difference between revisions

From North Forge
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:


     for part in (source..delimiter):gmatch("(.-)"..delimiter) do
     for part in (source..delimiter):gmatch("(.-)"..delimiter) do
         --if not (part ~= "") then
         if part~="" then --string is empty
             table.insert(results, string.format("<li>[[%s]]</li>", part))
             table.insert(results, string.format("<li>[[%s]]</li>", part))
         --end
         else
            table.insert(results, string.format("<li>%s</li>", part))
        end
     end
     end



Latest revision as of 00:04, 2024 August 17

This module implements some string functions to break apart semi-colon separate template parameters and turn them into links. This is so that a parameter setup to be digested into a Cargo list can be displayed without being pulled via query.

To use:

  • {{#invoke:String | splitAndLink | source={{{the template parameter you are split linking|}}} }}

-- Module:String
local p = {}

function p.splitAndLink(frame)
    local delimiter = frame.args.delimiter or ";"
    local source = frame.args.source or ""
    local results = {}

    for part in (source..delimiter):gmatch("(.-)"..delimiter) do
        if part~="" then --string is empty
            table.insert(results, string.format("<li>[[%s]]</li>", part))
        else
            table.insert(results, string.format("<li>%s</li>", part))
        end
    end

    return "<ul>" .. table.concat(results) .. "</ul>"
end

return p