Module:FAQ accordion

From Bootstrap for MediaWiki

Builds an accordion from questions and answers.

Usage

{{#invoke:FAQ accordion|faq
 |First question|First answer
 |Second question|Second answer
}}

Parameters

  • Questions and answers in pairs: each question is followed by its answer. The answers may contain wikitext, such as links.

Requirements

Example

See Accordion example 6.


-- Builds an accordion from pairs of question and answer
local p = {}

function p.faq( frame )
	local args = frame.args
	local cards = {}
	local i = 1
	while args[i] do
		-- The cards reach the accordion as tags, because only then do they know that they are inside it
		table.insert( cards, '<bootstrap_card heading="' .. mw.text.encode( mw.text.trim( args[i] ) ) .. '">' .. mw.text.trim( args[i + 1] or '' ) .. '</bootstrap_card>' )
		i = i + 2
	end
	return mw.bootstrap.parse( 'accordion', table.concat( cards, '\n' ), {} )
end

return p