Build content editable navigation items
If we take a look at our Navigation
component, notice that each link is hardcoded.
rendering\src\Navigation.tsx
...
<div className="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom">
<h5 className="my-0 mr-md-auto font-weight-normal">
<Link href="/">
<a className="text-dark">
<img src={`${publicUrl}/sc_logo.svg`} alt="Sitecore" />
</a>
</Link>
</h5>
<nav className="my-2 my-md-0 mr-md-3">
<a
className="p-2 text-dark"
href="https://jss.sitecore.com"
target="_blank"
rel="noopener noreferrer"
>
{t('Documentation')}
</a>
<Link href="/styleguide">
<a className="p-2 text-dark">{t('Styleguide')}</a>
</Link>
<Link href="/graphql">
<a className="p-2 text-dark">{t('GraphQL')}</a>
</Link>
</nav>
</div>
...
Let us move all of that data into Sitecore so that content editors can add, edit, and remove the links. We will utilize the General Link
field for this.
Create navigation templates
Create Sitecore templates for the navigation items.
- Navigate to
/sitecore/templates/Feature
- Create a Template folder and call it
Navigation
- Create a
Navigation Folder
template. It's purpose is to hold navigation items.- Under the
Navigation
folder you just created, right click > Insert New Template- Name:
Navigation Folder
- Base Template:
Templates/Common/Folder
- Name:
- Under the
- Create a
Navigation Item
template.- Under the
Navigation
folder, right click > Insert New Template- Name:
Navigation Item
- Base Template:
Templates/System/Templates/Standard template
- Name:
- For template section enter
Navigation Item
- Create a template field
Navigation Link
of the typeGeneral Link
- Under the
- Back on the
Navigation Folder
item- Create Standard Values
- Under the Standard Values, add the
Navigation Item
to the insert options.
- Set icons for both the
Navigation Folder
andNavigation Item
if you desire.
Your templates should look something like:
Create navigation items
From the navigation templates, we will create navigation items.
- Navigate to
/sitecore/content/XmNextJs
- Create a folder and call it
Navigation
- Under that folder, right click > Insert from Template
- Select your
/Feature/Navigation/Navigation Folder
- Name it
Header
- Select your
- Create Navigation items
- Create a navigation item under
Header
and call itDocumentation
- Under the
Navigation Link
, clickInsert external link
- Link description:
Documentation
. This is what is going to be rendered between the anchor tag. - URL:
https://jss.sitecore.com
- Under the
- Create another
Navigation Item
namedStyleguide
- Under the
Navigation Link
, clickInsert link
. - Select the
/sitecore/content/XmNextJs/home/styleguide
item - Description:
Styleguide
. This is what is going to be rendered between the anchor tag.
- Under the
- Create another
Navigation Item
namedGraphQL
- Under the
Navigation Link
, clickInsert link
- Select the
/XmNextJs/home/graphql
item - Description:
GraphQL
.
- Under the
- Create a navigation item under
Your items should look something like:
Now that we have some navigation items, let's take a look at how to query the items.