Overview
This template can build documentation either as a single tree or as a set of top-level categories. The behaviour is toggled by the category flag in config.php:
return [
// ...
'category' => false,
];
Turning the flag on switches the configurator into "category mode", which changes how collections are flattened, how menus are generated, and what sidebar a page receives.
When category is false
Configurator::prepare()callsmakeSingleStructure(), producing one flattened list for each locale.source/_core/collections.phpstill creates one collection per locale, and the sidebar is built from the entire tree returned by.settings.php.- Every page uses the same menu (
$page->configurator->getMenu($locale)), so the sidebar always reflects the full documentation tree.
This matches the default Jigsaw experience and is best for smaller documentation sets where a single sidebar is enough.
When category is true
-
Configurator::prepare()switches tomakeMultipleStructure()and instantiatesMultipleHandler. -
Each top-level entry defined in the locale root
.settings.phpmenuarray becomes a category. For example, insidesource/docs/en/.settings.php:return [ 'menu' => [ 'collections' => 'Collections', 'content' => 'Content', // ... ], ]; -
For every category key (such as
collections) the configurator:- Stores category-specific sidebar data through
MultipleHandler::setMenu()andsetFlatten(). - Keeps track of the first non-link menu item to use as the category's landing page.
- Exposes the data via
Configurator::getMenu($locale, [$locale, $category]).
- Stores category-specific sidebar data through
-
The global
getMenuhelper inconfig.phpdetects the flag and feeds the current page's first two path segments ($locale/$category) into the configurator, so only the relevant sidebar items appear. -
The top navigation (
$page->configurator->getTopMenu($locale)) is populated with category entries, giving users an easy way to jump between sections. -
Keys that start with
httporhttpsare treated as plain links byConfigurator::isLink(). They render in the top navigation (and anymenuarrays) as direct anchors and skip sidebar/category generation. You can mix directory-backed categories and link-only items in the same array:'menu' => [ 'collections' => 'Collections', 'https://example.com/design-system' => 'Design System', ];
This mode works best for large doc sets or when you want distinct landing pages per section. Each category directory can still contain nested folders with their own .settings.php files; the configurator will build sub-menus the same way as in single mode.
Directory shape in category mode
!folders
- {$DOCS_DIR}
- {$lang}
-- settings.php
- category1 -- .settings.php -- index.md
- category2 -- .settings.php -- index.md !endfolders
- {$lang}
-- settings.php
return [
'menu' => [
'category1' => 'Category1',
'category2' => 'Category2',
'https://example.com' => 'Link'
],
];
Ensure that each category folder has either an index.md or a file that matches the folder name (for example, collections/collections.md) so the configurator can mark the category as having a landing page.
Creating pages with the CLI
The helper script bin/docs-create.php accepts a --category=true|false flag when scaffolding new entries. When the global category mode is on, passing --category=true tells the script to create the page under the right category directory and wire up the .settings.php entry automatically.
Switching the flag
- Update
config.php(or setCATEGORY=truein.envif you prefer environment overrides). - Run
npm run devornpm run buildto rebuild the site so the configurator regenerates the menus. - Inspect the generated
_siteoutput: each locale will now expose either a unified sidebar (single mode) or category-specific sidebars with a top-level switcher (category mode).
If a sidebar appears empty after enabling categories, double-check that the .settings.php file at the locale root exposes the category key you expect and that the corresponding directory contains Markdown files.