Cosmos CMS Nav Builder¶
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?)
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.