Default Hierarchy Links in Sitecore SXA

Reading Time: 5 minutes

I have recently found out a hidden gem called Default Hierarchy Links in Sitecore SXA and wanted to share this knowledge with you.

When you are adding new Link components onto pages this popup opens:

sxa-links-00

This post is about exactly those Hierarchy links (Next sibling, Parent item, Previous sibling) and I will show you in which scenarios you can use them.

Sneak peak πŸ™‚ You can build these kind of navigation elements on pages:

sxa-links-23

Some background

We were building a page where we should have “Back button” (to go to parent item) and pager functionality with Next/Previous buttons.

I thought that I will add Link component to the page for this and then figure out the rest.

I was really curious what are the options in the dialog when it opened:

sxa-links-00

I wouldn’t have expected that it will solve our requirements straight away πŸ™‚

Solution

I will demonstrate this functionality on a Partial Design that I have created and has only “Title” and “Page Content” components so far:

sxa-links-01

Prepare Partial Design

Let’s add a “Link” component from “Navigation” section from Toolbox. Drag and drop it before “Title” component and choose “Parent Item”:

sxa-links-02

Add another “Link” component, this time below “Page Content” component and select “Previous sibling”:

sxa-links-03

Change the styling to have Size 6 for tablets:

sxa-links-04

Add another “Link” component and this time below the previously added “Link” component and select “Next sibling”:

sxa-links-05

To recap, this is how your partial design should look like as of now:

sxa-links-06

I have numbered the places where the links should have appeared.

Prepare Rendering Variants

I will show below how to create Rendering Variants for “Link” rendering/component. Obviously I did this just to quickly demonstrate you the functionality. Best would be to create separate / clone “Link” component and create these rendering variants there also in corresponding branch template. See my previous article about SXA extension / altering possibilities why should you do it this way.

For now duplicate three times “Default” Rendering Variant for Link:

sxa-links-07

Name these duplicates “Next”, “Previous”, “Back”.

For all duplicates remove everything under Link subitem.

For “Next” and “Previous”, add variant “Text” underneath:

sxa-links-07b

Keep “Tag” field empty and specify “Next” or “Previous” in “Text” accordingly. Check “Is Link”.

For “Back” add variant “Section” under Link and specify it like this:

sxa-links-08

Add variant “Text” under Section and put desired text in “Text” field. I have chosen “Back to ”

sxa-links-09

Mind the white space in “Text” field to nicely format output:

sxa-links-09b

Add / specify “Title” field like this:

sxa-links-10

This could be solved with only “Title” field having Prefix defined but this is not generating proper HTML. In this case it would be something like below which was not desired for us. Better is to use above approach.

sxa-links-22

Pro Tip: As a last step, change the order of rendering variants and make “Default” first one in the list. This is necessary to keep existing functionality like it was and make “Default” really the default. SXA works the way that when rendering variant is not specified, it will fallback to first variant… Have this always in mind!

You should have it like this:

sxa-links-21

Setting proper rendering variants

We have already prepared partial design and rendering variants.

Now it is the time to set newly created rendering variants in our partial design.

For the first / top link, select “Back” rendering variant:

sxa-links-11

For the bottom left link, select “Previous” rendering variant:

sxa-links-12

For the bottom right link, select “Next” rendering variant:

sxa-links-13

If you haven’t done so, select this Partial Design in your Page Design:

sxa-links-14

For demonstration purposes, I have created dummy structure of Pages like below. First one is “Parent Page” and it has five children:

sxa-links-15

Open one of the pages – Second, Third or Fourth – and you will see that the back button has correct text and also URL generated. Text is partly “hard-coded” with “Back to ” text proceeded with title of parent item:

sxa-links-16

Also the previous:

sxa-links-17

and Next:

sxa-links-18

What is really cool is that for first and last page, it will only generate necessary links.

For first page, it will omit “Previous” as there is no other sibling item above in the hierarchy:

sxa-links-19

On the other hand for the last / fifth page, it will omit “Next” button as there is no other sibling item below:

sxa-links-20

How many times have you build something similar?

With SXA, piece of cake, right? πŸ™‚

Happy varianting!

One comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.