Filtering: Highlighted Content Web Part

One of the struggles with Office 365 is figuring out when you should use certain web parts.

Problem: I need to display files from a document library’s subfolder on a webpage.

Solution: I first attempted this using a document library web part. As you could imagine, you run into the issue of displaying all subfolders in the document library instead of just drilling down to one folder. There is a workaround with this web part. You can create a column and tag the files associated with the subfolder with a piece of metadata and then build a view for the library based off of that. This works but it just wasn’t that clean.

Next, we tried out the highlighted content web part and attempted to mess around with a more advanced filter. To get to this location you will need to edit the web page and then edit the Highlighted Content web part.

Let’s first edit the modern page to see more options.

Edit modern page.PNG

Next, we will select the pencil icon next to the Highlighted Content web part so that we can access the edit menu.

edit highlighted content.png

The edit menu will appear on the right side of the web page. Select the Custom query radio button to get started with the CAML language.

custom query.PNG

This requires the use of CAML syntax. I looked online for examples and none of them represented quite what I was hoping to accomplish so I decided to understand the language a little better and write my own mini script. The result is show in the image below.

CAML syntax that filters a library down to designated subfolder.

CAML syntax that filters a library down to designated subfolder.

The “RecursiveALL” text in the scope line allows you to refine your search to one subfolder, which is COVID in this example. Otherwise, you will see all of the available files in the Shared Documents library.