Nav Builder Widget¶
Summary¶
Builds a simple list of links (child pages) under a given root path using the SkyCMS Table of Contents API.
- Location (source):
Editor/wwwroot/lib/cosmos/nav-builder.js - Primary API:
ccms___NavBuilder(pagePath, navElementId, liClassName?, anchorClassName?)
Outcome¶
After completing this guide, you should be able to render a navigation list for any valid root path and style it with optional list and anchor classes.
Steps¶
- Add a
<ul>or<ol>container element with the targetidto your page markup. - Include
nav-builder.jsin your layout or page template:<script src="/lib/cosmos/nav-builder.js"></script>. - Call
ccms___NavBuilder(pagePath, navElementId)after the DOM is ready, using the desired root path without a leading slash. - Optionally pass
liClassNameandanchorClassNameto apply CSS classes to generated list items and links. - Load the page and verify the navigation list renders with the correct child-page links.
How it works¶
- Fetches
/Home/GetTOC?page=/{pagePath}(GET) and expects JSON with anItemsarray. - For each item, takes the last segment of
item.Titlefor link text and uses"/" + item.UrlPathfor thehref. - Appends
<li><a></a></li>to the container withid=navElementId.
Minimal HTML example¶
<ul id="ulNav" class="nav flex-column"></ul>
<script src="/lib/cosmos/nav-builder.js"></script>
<script>
// Build navigation for children under "/docs"
// li gets Bootstrap class "nav-item" and anchor gets "nav-link"
ccms___NavBuilder('docs', 'ulNav', 'nav-item', 'nav-link');
</script>
Notes¶
- Ensure the element with
navElementIdexists before invoking. pagePathshould not include a leading slash.- You can omit
liClassNameand/oranchorClassNameto avoid adding classes.
Verification¶
This integration is complete when the helper renders expected child-page links and each generated URL resolves to the intended page.