Forum Discussion

gretesh's avatar
gretesh
Copper Contributor
Aug 04, 2023
Solved

Custom thumbnail images with a fallback to default ones

Hi all, I want to set up my SharePoint view (first the List, later also the Tiles view) so that it would show thumbnails for each file and folder.   Some files in the folders already show a default...
  • ganeshsanap's avatar
    ganeshsanap
    Aug 07, 2023

    gretesh Seems like Thumbnail is kind of reserved/default column name in SharePoint libraries. Try using this JSON: 

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "=getThumbnailImage([$Thumbnail], 50, 50)"
          },
          "style": {
            "display": "=if([$Thumbnail.serverRelativeUrl]=='', 'none', 'block')",
            "height": "50px"
          }
        },
        {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.small"
          },
          "style": {
            "display": "=if([$Thumbnail.serverRelativeUrl]=='', 'block', 'none')",
            "height": "50px"
          }
        }
      ]
    }

     

    For safer side, I will suggest you to create a Image column with different name (say CustomThumbnail) and then use JSON like below in Image column: 

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "=getThumbnailImage([$CustomThumbnail], 50, 50)"
          },
          "style": {
            "display": "=if([$CustomThumbnail.serverRelativeUrl]=='', 'none', 'block')",
            "height": "50px"
          }
        },
        {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.small"
          },
          "style": {
            "display": "=if([$CustomThumbnail.serverRelativeUrl]=='', 'block', 'none')",
            "height": "50px"
          }
        }
      ]
    }

     

    I have tested both the JSON and working fine for me.

     

    Output


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Resources