Forum Discussion
Any way to exclude Templates folder from Highlighted Content Web Part?
Hi DavidWexelblat
You could ditch the "Highlighted Contents" webparts and then create a new view on the "Site Pages" library. Exclude the content type "Folder" and sort that view by the "modified date" descending.
As templates are stored in the "templates" folder in that document library these will not be visible as we excluded folders from the view.
Instead of the "Highlighted Contents" webpart add a "Document Library" webpart and select the "Site Pages" Library and your new view. Disable the "Show command bar" and "Show See all button" toggles.
But that does not look like the "Hightlighted Contents" webpart.
If you don't like the list look of that webpart, you can go back to the view settings and switch the view type from list to tiles. Or you need to create a View Formatting that looks like the "Hightlighted Contents" webpart like this sample https://github.com/pnp/List-Formatting/tree/master/view-samples/document-library-gallery-card
Best Regards,
Sven
- DavidWexelblatJun 06, 2023Brass Contributor
Thanks SvenSieverding. I'd already looked at using a doc library view for this, but I don't want a list and wasn't impressed with tiles. I am not experienced with custom json formatting; that example you linked kinda blows my mind. I will dig into that deeper.
This really should be built-in. There's no reason whatsoever for items in the Templates folder to ever be included in "highlighted content"...- DavidWexelblatJun 06, 2023Brass ContributorSvenSieverding - I played around with that JSON formatting, and it's way beyond me. That example didn't work as is (I know parts of it are looking for specific fields, but I didn't even get any thumbnail images in my grid, and got completely lost trying to figure that out).
I decided to try doing a calculated field to look for a specific tag in the page title, which was easy to do - but HCWP doesn't show the calculated field as a "page attribute" for filtering, only title and a couple of choice fields I set up as page metadata. Sigh.
So I came up with another solution - using a CAML query with "Scope='FilesOnly'" on the <View> tag. CAML doesn't traverse folders by default, and this keeps the "Templates" folder itself from showing up in the results.
It works, but I'm not a fan of needing to build CAML queries for what should be simple stuff. Makes page maintenance and reuse far more hassle than it should be.- Jun 06, 2023Just use KQL in the highlighted webpart and add what you want to display in the kql and add"-path:{Full Path}*" to exclude everything within a certain path.
No reason to reinvent the wheel