Module:Collapsible: Difference between revisions
Chalochatu (talk | contribs) Created page with "local p = {} function p.collapsible(frame) -- Prefer your local Module:Collapsible list if it exists local ok, m = pcall(require, 'Module:Collapsible list') if ok and m and type(m.main) == 'function' then return m.main(frame) end -- Fallback to Module:Navbox if your setup routes collapsible lists via Navbox local ok2, nav = pcall(require, 'Module:Navbox') if ok2 and nav and type(nav.navbox) == 'function' then -- Pass through unchanged; may not render as a li..." |
Chalochatu (talk | contribs) No edit summary |
||
| Line 2: | Line 2: | ||
function p.collapsible(frame) | function p.collapsible(frame) | ||
-- Prefer | -- Prefer Collapsible list → main | ||
local ok, | local ok, mod = pcall(require, 'Module:Collapsible list') | ||
if ok and | if ok and mod and type(mod.main) == 'function' then | ||
return | return mod.main(frame) | ||
end | end | ||
-- | -- Optional fallback: Navbox → navbox (if present on your wiki) | ||
local ok2, nav = pcall(require, 'Module:Navbox') | local ok2, nav = pcall(require, 'Module:Navbox') | ||
if ok2 and nav and type(nav.navbox) == 'function' then | if ok2 and nav and type(nav.navbox) == 'function' then | ||
return nav.navbox(frame) | return nav.navbox(frame) | ||
end | end | ||
return 'Module error: expected Module:Collapsible list.main or Module:Navbox.navbox to handle "collapsible".' | |||
return 'Module error: | |||
end | end | ||
return p | return p | ||
Latest revision as of 08:17, 19 September 2025
This module is a small compatibility shim that exposes a function named collapsible. It forwards calls to an available renderer so that legacy templates using Script error: No such module "…". do not break.
Purpose
Some imported templates call:
or
Script error: The function "collapsible" does not exist.
On Chalo Chatu the primary entrypoint is main in Module:Collapsible list. This shim looks for that first; if unavailable, it may fall back to a compatible function in Module:Navbox (if present). If neither exists, it returns a clear error message.
Usage
Prefer the direct entrypoint:
Only use this shim for legacy code that cannot be edited:
Parameters
Identical to Module:Collapsible list’s main:
- title / header
- Heading text.
- collapsed
- yes / no. Adds class collapsed when yes.
- 1..50
- Positional items.
- class, id, list_style, item_style
- Optional styling hooks passed through when supported.
Behavior
- If Module:Collapsible list with function main(frame) exists, all arguments are forwarded to it.
- Else, if Module:Navbox with function navbox(frame) exists, arguments are forwarded as-is (output may differ).
- Else, a readable Module error string is returned.
Migration guidance
Where possible, update templates to call:
This reduces indirection and makes behavior explicit.
Troubleshooting
- If you still see "Script error: The function 'collapsible' does not exist", ensure this page (Module:Collapsible) is created and that Module:Collapsible list exists with a main function.
- If output appears but styling looks plain, add CSS for .chalo-collapsible classes in MediaWiki:Common.css.
See also
local p = {}
function p.collapsible(frame)
-- Prefer Collapsible list → main
local ok, mod = pcall(require, 'Module:Collapsible list')
if ok and mod and type(mod.main) == 'function' then
return mod.main(frame)
end
-- Optional fallback: Navbox → navbox (if present on your wiki)
local ok2, nav = pcall(require, 'Module:Navbox')
if ok2 and nav and type(nav.navbox) == 'function' then
return nav.navbox(frame)
end
return 'Module error: expected Module:Collapsible list.main or Module:Navbox.navbox to handle "collapsible".'
end
return p