Anchors

25 views
Skip to first unread message

Name

unread,
Dec 17, 2019, 5:44:32 PM12/17/19
to CrafterCMS
Hi,

Is there a way to allow users to dynamically add anchors to the navigation? We've been successful in doing so using redirects, however, this obviously refreshes the page.

Jose Ross

unread,
Dec 18, 2019, 9:21:14 AM12/18/19
to CrafterCMS
Hello, can you please provide more information about your setup? are you using the freemarker templates to generate a dynamic navigation?

Name

unread,
Dec 18, 2019, 3:56:08 PM12/18/19
to CrafterCMS
Hi,

Yes, I'm using the nav-macros similar to the default Editorial site. 

Jose Ross

unread,
Dec 18, 2019, 4:20:43 PM12/18/19
to CrafterCMS
There are a couple of features that could be useful for this:
  1. Custom Navigation Attributes: using this feature you can make the dynamic navigation include more fields than just the url and the label. You will need to add a field in your content-types (something like an input with name navigationAnchor) and then add this property in your Engine Site Configuration File:
    <navigation>
    <additionalFields>navigationAnchor</additionalFields>
    </navigation>

  2. Custom Navigation Macros: using this feature you can change the template in any way to use the custom attribute added in the previous step, something like this:
    <#macro renderNavItem navItem>
    <li <#if navItem.active>class="active"</#if>><a href="${navItem.url}#${navItem.attributes.navigationAnchor}">${navItem.label}</a></li>
    </#macro>

Reply all
Reply to author
Forward
0 new messages