SharePoint Online – Change Highlighted Content WebPart

Posted by

Many of us are aware that one of the best web parts that is available on the modern pages is highlighted content web part.  It has the capability to aggregate the content across multiple site collections and we can also apply filters on the content.  It offers different layout for data presentation on the UI.

In this blog post, I will show you how you can change the UI of the highlighted content web part.  I will take an example of one of the layouts (List layout) to make the changes and the same principle applies to different layouts as well.

I have a document library by name Videos to store the videos categorized under different subjects and knowledge levels. I also have a metadata that determines if the video should be visible on the highlighted content web part.

The highlighted content web part that fetches the information from this library and filters the content based on Planner is as shown below.

In the above screen image on the right-hand side we have used highlighted content web part and we get the desired filtered content from our Videos library.  However, from the UI perspective we can make some improvements by removing/altering unnecessary elements like modifying the header Title as Videos.  I also would like to remove the file icon (file type) against each of the videos.

To start with, I first export the site using DevPnP command

Get-PnPProvisioningTemplte -Out "D:\StandardTeam.xml"

Here is my StandardTeam.xml example that got exported and within the <pnp:ClientSidePages> you have Home.aspx page which contains 2 ConvanControl.  One corresponds to News app and another (ContentRollup) is for highlighted content web part.

Copy the JsonControlData and paste it in a text file.  The json data in the text file is HTML encoded. So replace

After you replace these, the json data will be much more readable.  We must change the json data so that our requirements are met.  The best way to change the json data is with the help of a json editor and for this I use https://jsoneditoronline.org/

You can use any editor of your choice.

A bit of interpretation of the json data shows that the layoutId is List and templateId is 2 that corresponds to List layout.  The displayMaps has 4 different objects each corresponding to 4 different layouts offered by highlighted content web part.

So, our interest is List layout whose templateId is 2 and hence expanding the displayMaps 2 shows us that it has 4 different columns FileType, Title, ModifiedDate and ModifiedBy.  We can add/remove/alter the columns here.

Let us remove the column1
FileType, column3
Modified and column4
ModifiedBy. We also rename the column 2 heading from Title to Videos.

So, this is how our modified json looks like. Click on the < arrow so that the data is synchronized between the json text editor and visual hierarchical representation on the jsoneditor.

Since we have made all the desired changes, we must now make this json data compatible with our template and for this, we must replace

Copy the json data and replace with the old json data in the StandardTeam.xml template.  Before we apply our template to the site, we shall clean-up all the unnecessary things in the StandardTeam.xml so that we can focus on provisioning only the Home.aspx page with the changes that we incorporated.  So, I delete all the elements except client pages, and this is how the StandardTeam.xml looks like

Apply this template using the DevPnP command

Apply-PnPProvisioningTemplate -Path “D:\StandardTeam.xml”

Bingo, we get our desired results. So, this way we can use highlighted content web part and modify the UI as per our needs.

You can make changes to the items retrieved by highlighted content web part by modifying the CAML query that is associated within this web part. An example of the CAML query that I got from this same is,

<View Scope="RecursiveAll"&gt;
        <Query&gt;
            <Where&gt;
                <And&gt;
                    <Eq&gt;
                        <FieldRef Name="SubjectCategory" /&gt;
                        <Value Type="MultiChoice"&gt;Planner</Value&gt;
                    </Eq&gt;
                    <Eq&gt;
                        <FieldRef Name="FSObjType" /&gt;
                        <Value Type="Integer"&gt;0</Value&gt;
                    </Eq&gt;
                </And&gt;
            </Where&gt;
            <OrderBy&gt;
                <FieldRef Name="SortOrder" Ascending="true" /&gt;
            </OrderBy&gt;
        </Query&gt;
        <ViewFields&gt;
            <FieldRef Name="Editor" /&gt;
            <FieldRef Name="FileLeafRef" /&gt;
            <FieldRef Name="File_x0020_Type" /&gt;
            <FieldRef Name="ID" /&gt;
            <FieldRef Name="Modified" /&gt;
            <FieldRef Name="Title" /&gt;
            <FieldRef Name="UniqueID" /&gt;
            <FieldRef Name="_ShortcutUrl" /&gt;
        </ViewFields&gt;
        <RowLimit Paged="false"&gt;8</RowLimit&gt;
    </View&gt;

In the above code snippted you see that I have used SortOrder, which is a field of type Number that I created and it lets me sort the items on the highlighted content web part.

The highlighted content web part which is available on modern pages of SharePoint Online has the JSON data and the CAML query is embedded within it, that helps us to add our own query filters and sort order. Someone with good CAML understanding must be very much excited to leverage such hidden incredible capabilities.

2 comments

Comments are closed.