0

I would like to display images in a thumbnail/Tile view but also with multiple links to different resolution of the image. It works ok in a list view when i click on the images.

But can't even get the link to display in the Tile view I want this layout. Thanks in Advance

enter image description here

See my snippet below

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/tile-formatting.schema.json",
    "height": 423,
    "width": 254,
    "hideSelection": false,
    "fillHorizontally": true,
    "formatter": {
      "elmType": "div",
      "attributes": {
        "class": "sp-card-container"
      },
      "children": [
        {
          "elmType": "div",
          "attributes": {
            "class": "sp-card-defaultClickButton"
          },
          "customRowAction": {
            "action": "defaultClick"
          }
        },
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-white sp-css-borderColor-neutralLight sp-card-borderHighlight sp-card-subContainer"
          },
          "children": [
            {
              "elmType": "div",
              "attributes": {
                "class": "sp-card-previewColumnContainer"
              },
              "children": [
                {
                  "elmType": "div",
                  "attributes": {
                    "class": "sp-card-imageContainer"
                  },
                  "children": [
                    {
                      "elmType": "filepreview",
                      "attributes": {
                        "src": "@thumbnail.512x432"
                      },
                      "style": {
                        "height": "200px"
                      },
                      "filePreviewProps": {
                        "fileTypeIconClass": "sp-fileTypeIcon-cardDesigner",
                        "brandTypeIconClass": "sp-brandTypeIcon-cardDesigner"
                      }
                    }
                  ]
                }
              ]
            },
            {
              "elmType": "div",
              "attributes": {
                "class": "sp-card-displayColumnContainer"
              },
              "children": [
                {
                  "elmType": "p",
                  "attributes": {
                    "class": "ms-fontColor-neutralSecondary sp-card-label"
                  },
                  "txtContent": "[!FileLeafRef.DisplayName]"
                },
                {
                  "elmType": "p",
                  "attributes": {
                    "class": "ms-fontColor-neutralPrimary sp-card-content sp-card-highlightedContent sp-card-keyboard-focusable"
                  },
                  "txtContent": "[$FileLeafRef]",
                  "defaultHoverField": "[$FileLeafRef]"
                }
              ]
            },
            {
              "elmType": "div",
              "attributes": {
                "class": "sp-card-displayColumnContainer"
              },
              "children": [
                {
                  "elmType": "p",
                  "attributes": {
                    "class": "ms-fontColor-neutralSecondary sp-card-label"
                  },
                  "txtContent": "[!Editor.DisplayName]"
                },
                {
                  "elmType": "div",
                  "attributes": {
                    "class": "ms-fontColor-neutralPrimary sp-card-userContent ",
                    "title": "[$Editor.title]"
                  },
                  "children": [
                    {
                      "elmType": "p",
                      "txtContent": "=if(length([$Editor]) == 0, '–', '')"
                    },
                    {
                      "forEach": "personIterator in [$Editor]",
                      "elmType": "p",
                      "defaultHoverField": "[$personIterator]",
                      "style": {
                        "display": "=if(loopIndex('personIterator') >= 1, 'none', '')"
                      },
                      "txtContent": "[$personIterator.title]"
                    },
                    {
                      "elmType": "p",
                      "txtContent": "=if(length([$Editor]) > 1, ',  +' + (length([$Editor]) - 1) , '')"
                    }
                  ]
                }
              ]
            },
            {
              "elmType": "div",
              "attributes": {
                "class": "sp-card-displayColumnContainer"
              },
              "children": [
                {
                  "elmType": "p",
                  "attributes": {
                    "class": "ms-fontColor-neutralSecondary sp-card-label"
                  },
                  "txtContent": "[!Modified.DisplayName]"
                },
                {
                  "elmType": "p",
                  "attributes": {
                    "title": "=if ([$Modified.displayValue] == '', '–', [$Modified.displayValue])",
                    "class": "ms-fontColor-neutralPrimary sp-card-content "
                  },
                  "txtContent": "=if ([$Modified.displayValue] == '', '–', [$Modified.displayValue])"
                }
              ]
            },
            {
              "elmType": "div",
              "attributes": {
                "class": "sp-card-lastTextColumnContainer"
              },
              "children": [
                {
                  "elmType": "a",
                  "style": {
                    "border-radius": "5px",
                    "margin": "5px 0px",
                    "padding": "5px",
                    "border": "3px",
                    "text-decoration": "none",
                    "font-weight": "bold",
                    "color": "black",
                    "background-color": "lightblue"
                  },
                  "txtContent": "..",
                  "attributes": {
                    "target": "_blank",
                    "href": "https://xxxxxx.sharepoint.com/sites/PhotoLibrary/_layouts/15/getpreview.ashx?resolution=1&path=' + [$FileRef]"
                  }
                },
                {
                  "elmType": "span",
                  "txtContent": " | "
                }
              ]
            }
          ]
        }
      ]
    }
  }

1 Answer 1

1

Your main issue is with this piece of code:

"children": [
    {
      "elmType": "div",
      "attributes": {
        "class": "sp-card-defaultClickButton"
      },
      "customRowAction": {
        "action": "defaultClick"
      }
    }

With this, when you click on the card, the item will be open. If you delete this, you can select the card, and click on the custom Small/Medium/Large links!

There is also an issue with the URL concatenation.

Here's the working code:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/tile-formatting.schema.json",
  "height": 423,
  "width": 254,
  "hideSelection": false,
  "fillHorizontally": true,
  "formatter": {
    "elmType": "div",
    "attributes": {
      "class": "sp-card-container"
    },
    "children": [
      {
        "elmType": "div",
        "attributes": {
          "class": "ms-bgColor-white sp-css-borderColor-neutralLight sp-card-borderHighlight sp-card-subContainer"
        },
        "children": [
          {
            "elmType": "div",
            "attributes": {
              "class": "sp-card-previewColumnContainer"
            },
            "children": [
              {
                "elmType": "div",
                "attributes": {
                  "class": "sp-card-imageContainer"
                },
                "children": [
                  {
                    "elmType": "filepreview",
                    "attributes": {
                      "src": "@thumbnail.512x432"
                    },
                    "style": {
                      "height": "200px"
                    },
                    "filePreviewProps": {
                      "fileTypeIconClass": "sp-fileTypeIcon-cardDesigner",
                      "brandTypeIconClass": "sp-brandTypeIcon-cardDesigner"
                    }
                  }
                ]
              }
            ]
          },
          {
            "elmType": "div",
            "attributes": {
              "class": "sp-card-displayColumnContainer"
            },
            "children": [
              {
                "elmType": "p",
                "attributes": {
                  "class": "ms-fontColor-neutralSecondary sp-card-label"
                },
                "txtContent": "[!FileLeafRef.DisplayName]"
              },
              {
                "elmType": "p",
                "attributes": {
                  "class": "ms-fontColor-neutralPrimary sp-card-content sp-card-highlightedContent sp-card-keyboard-focusable"
                },
                "txtContent": "[$FileLeafRef]",
                "defaultHoverField": "[$FileLeafRef]"
              }
            ]
          },
          {
            "elmType": "div",
            "attributes": {
              "class": "sp-card-displayColumnContainer"
            },
            "children": [
              {
                "elmType": "p",
                "attributes": {
                  "class": "ms-fontColor-neutralSecondary sp-card-label"
                },
                "txtContent": "[!Editor.DisplayName]"
              },
              {
                "elmType": "div",
                "attributes": {
                  "class": "ms-fontColor-neutralPrimary sp-card-userContent ",
                  "title": "[$Editor.title]"
                },
                "children": [
                  {
                    "elmType": "p",
                    "txtContent": "=if(length([$Editor]) == 0, '–', '')"
                  },
                  {
                    "forEach": "personIterator in [$Editor]",
                    "elmType": "p",
                    "defaultHoverField": "[$personIterator]",
                    "style": {
                      "display": "=if(loopIndex('personIterator') >= 1, 'none', '')"
                    },
                    "txtContent": "[$personIterator.title]"
                  },
                  {
                    "elmType": "p",
                    "txtContent": "=if(length([$Editor]) > 1, ',  +' + (length([$Editor]) - 1) , '')"
                  }
                ]
              }
            ]
          },
          {
            "elmType": "div",
            "attributes": {
              "class": "sp-card-displayColumnContainer"
            },
            "children": [
              {
                "elmType": "p",
                "attributes": {
                  "class": "ms-fontColor-neutralSecondary sp-card-label"
                },
                "txtContent": "[!Modified.DisplayName]"
              },
              {
                "elmType": "p",
                "attributes": {
                  "title": "=if ([$Modified.displayValue] == '', '–', [$Modified.displayValue])",
                  "class": "ms-fontColor-neutralPrimary sp-card-content "
                },
                "txtContent": "=if ([$Modified.displayValue] == '', '–', [$Modified.displayValue])"
              }
            ]
          },
          {
            "elmType": "div",
            "attributes": {
              "class": "sp-card-lastTextColumnContainer"
            },
            "children": [
              {
                "elmType": "a",
                "style": {
                  "border-radius": "5px",
                  "margin": "5px 0px",
                  "padding": "5px",
                  "border": "3px",
                  "text-decoration": "none",
                  "font-weight": "bold",
                  "color": "black",
                  "background-color": "lightblue"
                },
                "txtContent": "Small",
                "attributes": {
                  "target": "_blank",
                  "href": {
                    "operator": "+",
                    "operands": [
                      "/_layouts/15/getpreview.ashx?path=",
                      "[$FileRef]",
                      "&resolution=1"
                    ]
                  }
                }
              },
              {
                "elmType": "span",
                "txtContent": " | "
              },
              {
                "elmType": "a",
                "style": {
                  "border-radius": "5px",
                  "margin": "5px 0px",
                  "padding": "5px",
                  "border": "3px",
                  "text-decoration": "none",
                  "font-weight": "bold",
                  "color": "black",
                  "background-color": "lightblue"
                },
                "txtContent": "Medium",
                "attributes": {
                  "target": "_blank",
                  "href": {
                    "operator": "+",
                    "operands": [
                      "/_layouts/15/getpreview.ashx?path=",
                      "[$FileRef]",
                      "&resolution=2"
                    ]
                  }
                }
              },
              {
                "elmType": "span",
                "txtContent": " | "
              },
              {
                "elmType": "a",
                "style": {
                  "border-radius": "5px",
                  "margin": "5px 0px",
                  "padding": "5px",
                  "border": "3px",
                  "text-decoration": "none",
                  "font-weight": "bold",
                  "color": "black",
                  "background-color": "lightblue"
                },
                "txtContent": "Large",
                "attributes": {
                  "target": "_blank",
                  "href": {
                    "operator": "+",
                    "operands": [
                      "/_layouts/15/getpreview.ashx?path=",
                      "[$FileRef]",
                      "&resolution=3"
                    ]
                  }
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

tiles view format view

Follow up of this topic: Different image resolution in SharePoint Online

1
  • 1
    Thanks jleture. you are a legend
    – naijacoder
    Commented Dec 5, 2023 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.