Accordion example 6
From Bootstrap for MediaWiki
| Component | ||
|---|---|---|
| Name | Accordion | |
| Description | Accordion built in Lua from pairs of question and answer | |
| Provider | BootstrapComponents | |
| Note | Needs the Scribunto extension, which runs Lua modules on the wiki. | |
| Reference | BootstrapComponents Extension docs - Lua | |
| Styling | For all possible color styles and corresponding examples, see colors. | |
Accordion from question and answer pairs
- Module
-- 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
- Code
{{#invoke:FAQ accordion|faq
|What is Bootstrap?|The [[Bootstrap (framework)|Bootstrap framework]] is a popular open-source front-end framework for building responsive websites.
|How does Bootstrap get into MediaWiki?|The [[Bootstrap (extension)|Bootstrap extension]] provides it, and the [[Chameleon]] skin installs that extension automatically.
|What does BootstrapComponents add?|The [[BootstrapComponents]] extension adds tags and parser functions for components that need HTML tags MediaWiki does not allow.
}}
- Result
What is Bootstrap?
The Bootstrap framework is a popular open-source front-end framework for building responsive websites.
How does Bootstrap get into MediaWiki?
The Bootstrap extension provides it, and the Chameleon skin installs that extension automatically.
What does BootstrapComponents add?
The BootstrapComponents extension adds tags and parser functions for components that need HTML tags MediaWiki does not allow.
