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

Module:String

From North Forge
Revision as of 18:59, 2024 June 16 by Ttenbergen (talk | contribs) (Created page with "-- Module:String local p = {} function p.split(frame) local delimiter = frame.args.delimiter or ";" local source = frame.args.source or "" local template = frame.args.template or "" local results = {} for part in (source..delimiter):gmatch("(.-)"..delimiter) do table.insert(results, frame:expandTemplate{title = template, args = {part}}) end return table.concat(results) end return p")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.split(frame)
    local delimiter = frame.args.delimiter or ";"
    local source = frame.args.source or ""
    local template = frame.args.template or ""
    local results = {}
    
    for part in (source..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(results, frame:expandTemplate{title = template, args = {part}})
    end

    return table.concat(results)
end

return p