Forum Discussion

DavidWexelblat's avatar
DavidWexelblat
Brass Contributor
Jun 02, 2023

Any way to exclude Templates folder from Highlighted Content Web Part?

I am trying to figure out a way to exclude pages under "Site Pages/Templates" from the Highlighted Content Web Part (Source = "The page library on this site"). Using a static metadata column doesn't work, because any page created from that template will carry that metadata field along with it, making it impossible to distinguish templates from pages with that field.

I've been trying to figure out how to do this with a calculated column, but the only solution I've come up with at this point is to put a bogus key string in the template's page title, then create a calculated field that distinguishes between pages and templates based on the presence of that substring in the page title. But that causes the bogus key string to appear in the template name in the New Page templates gallery, which is ugly.

7 Replies

  • SvenSieverding's avatar
    SvenSieverding
    Bronze Contributor

    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

    • DavidWexelblat's avatar
      DavidWexelblat
      Brass 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"...

      • DavidWexelblat's avatar
        DavidWexelblat
        Brass Contributor
        SvenSieverding - 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.

Resources