Randy Wink
Randy Wink

Reputation: 71

Sitecore SXA - Multi-Root TreeList - Data Source Query

Within our Sitecore SXA 1.9 project, we're having a Template with a Multi-Root Treelist field.

This field has the following query:

query:/sitecore/content/Event Sites//*[@@name='Home']

As a result, the field is populated as:

Multi-Root Treelist populated by query

Would it be possible to display the actual website names instead of '(Current Site)'?

Upvotes: 0

Views: 891

Answers (1)

Jean-Nicolas G.
Jean-Nicolas G.

Reputation: 239

If you are using this code (https://gist.github.com/kamsar/33d1245ffdb630b1f126) for multi root treelist, then you should be able by creating a custom MultiRootTreeView by extending MultiRootTreeView and use it instead of the default Sitecore.Web.UI.WebControls.MultiRootTreeview()

Create a custom tree view here (adjust according to your need btw)

using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Web.UI.WebControls;

namespace Sitecore.Foundation.SitecoreExtensions.FieldTypes
{
    public class EnhancedMultiRootTreeview : MultiRootTreeview
    {
        protected override string GetHeaderValue(Item item)
        {
            Assert.ArgumentNotNull(item, "item");

            var nodeTitle = string.IsNullOrEmpty(DisplayFieldName) ? item.DisplayName : item[DisplayFieldName];

            return $"{nodeTitle}  -  <span>({item.Paths.ContentPath})</span>";
        }
    }
}

Use your Custom MultiRootTreeview here (within your MultiRootTreeList Implementation)

var impostor = new EnhancedMultiRootTreeview
{
   ID = existingTreeView.ID,
   DblClick = existingTreeView.DblClick,
   Enabled = existingTreeView.Enabled,
   DisplayFieldName = existingTreeView.DisplayFieldName
};

Upvotes: 0

Related Questions