Forum Discussion
Any way to exclude Templates folder from Highlighted Content Web Part?
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"...
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- DavidWexelblatJun 07, 2023Brass Contributor
CAML, not KQL, since I'm using "The page library on this site", and that's what I did, as I noted in the post above your reply.
But I had to spend well over an hour figuring out how to make this CAML query, never having done it before (learning the syntax, discovering the "Scope" parameters, etc.), for something that shouldn't even be necessary - there's no way templates should be included in "highlighted content" when the page library is the source. It makes absolutely no sense.
And having to tailor queries is a far bigger PITA than selecting fields on the filter UI, which makes this approach problematic for page maintenance/site reuse. I'm the only one on my team who has any chance of sorting out queries at this level. My non-tech-savvy content collaborators shouldn't have to deal with this complexity for something so simple.
- Jun 07, 2023Yeah Caml query is super old school and shouldn't be used. That's why I said KQL 🙂 KQL query is a lot easier and more modern, just say path, type and what you need to exclude 🙂