Sometimes user wants to pass some additional information about the Structure Group (Like Short Title or Alternative Title), in that case this solution will help to achieve their functionality without any code change on CMS side. Here I have updated the DXA default Generate Sitemap Template in such a generic way that user can easily pass additional info via Navigation.Json to Web Application.
Scenario:
Imagine client wants to show short title for structure group in the top navigation in case of Mobile and Tab view. Let me show how easily you can achieve this –
1st Step >
You have to Create a Meta Data Schema which will hold the additional info of Structure Group-
Here I have created One Sample Schema Just as an example -
and added 2 Schema fields like below(You can configure it as per your requirement) -
XML Name | Description | Type |
alternativeTitle | Alternative Title (By default it will show the Structure Group Title, This field is helpful if you want to show different Title) | Text |
shortTitle | Short Title (Additional filed to show the short form of Structure Group. More useful for Mobile/Tab View) | Text |
2nd Step>
Edit the existing Navigation Configuration Schema
- Added 2 schema fields in the Metadata Design of Navigation Configuration Schema
XML Name | Description | Type |
metaDataSchema | Metadata Schema used to pass additional data to Sitemap Json from Structure Group (leave blank if additional data not required in navigation) | Text |
metaDataFields | Used to specify the fields name want to pass from Metadata Schema (comma separated list of field names to get the field value from Structure Group Metadata) | Text |
3rd Step>
Update existing Navigation Configuration Component -
Here you can see I have added the Name of the Metadata Schema in the metaDataSchema filed. And mentioned all the schema fields in metaDataFields which I wanted to add in the navigation json.
So base is ready. Now download the template from here. Build it and upload the dll into the existing Generate Sitemap Template Building Blocks.
Create a test Structure Group and add the additional data for test. Here is a sample for that –
Now if you select _Navigation Page and click on Preview, you can see your data in the under AdditionalData field.
In future if you need to pass more data, then just need to add the field in the metadata schema and update the field name in the Navigation Configuration Schema and you will be ready.
Note*: As of now the code was written for string type value, for other data type (like Component Link or Keyword, etc.) you need to customize that code accordingly.
On the web application side you can create a dictionary or a model called AdditionalData and easily fetch the value from Custom Sitemap Model
So here is the AdditionalData Model:
That’s it. Use it and Enjoy..