Module:Badge list

From Bootstrap for MediaWiki

Turns a comma-separated list into badges, for example the keywords of an infobox.

Usage

{{#invoke:Badge list|list|Chameleon, Medik, Tweeki|color=primary}}

Parameters

  • The first parameter: the items, separated by commas. Empty items are left out.
  • color: the color of the badges, for example primary or success; see colors. Without it, the badges are secondary.

Requirements

Example

See Badge extension example 3.


-- Turns a comma-separated list into badges, for example the keywords of an infobox
local p = {}

function p.list( frame )
	local color = frame.args.color or 'secondary'
	local badges = {}
	for item in mw.text.gsplit( frame.args[1] or '', ',', true ) do
		item = mw.text.trim( item )
		if item ~= '' then
			table.insert( badges, mw.bootstrap.parse( 'badge', item, { color = color, pill = true } ) )
		end
	end
	return table.concat( badges, ' ' )
end

return p