More actions
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" |
Ttenbergen (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
local p = {} | local p = {} | ||
function p. | function p.splitAndLink(frame) | ||
local delimiter = frame.args.delimiter or ";" | local delimiter = frame.args.delimiter or ";" | ||
local source = frame.args.source or "" | local source = frame.args.source or "" | ||
local results = {} | local results = {} | ||
for part in (source..delimiter):gmatch("(.-)"..delimiter) do | for part in (source..delimiter):gmatch("(.-)"..delimiter) do | ||
table.insert(results, | table.insert(results, string.format("<li>[[%s]]</li>", part)) | ||
end | end | ||
return table.concat(results) | return "<ul>" .. table.concat(results) .. "</ul>" | ||
end | end | ||
return p | return p |
Revision as of 19:12, 2024 June 16
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
table.insert(results, string.format("<li>[[%s]]</li>", part))
end
return "<ul>" .. table.concat(results) .. "</ul>"
end
return p