1

I've create a SharePoint list with clickable image from a link column, more info over here: SharePoint list formatting image column with clickable link from another column

Now I'm trying to fix an error, when the link column is empty it's create a faulty link instead of showing no link. I've tried the code below this but hides the image too.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "style":{
    "display":  "=if([$MyLinkColumn]=='','none','block'" 
  },
  "attributes": {
    "target": "_blank",
    "href": "[$MyLinkColumn]"
  },
  "children": [
    {
      "elmType": "img",
      "style": {
        "display": "block",
        "background-color": "none",
        "position": "relative",
        "width": "60px"
      },
      "attributes": {
        "src": "@currentField.serverRelativeUrl"
      }
    }
  ]
}

1 Answer 1

1

Try using this JSON on your Image column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "a",
      "attributes": {
        "target": "_blank",
        "href": "[$Link]"
      },
      "style": {
        "display": "=if([$Link]!='','block','none')"
      },
      "children": [
        {
          "elmType": "img",
          "style": {
            "display": "block",
            "background-color": "none",
            "position": "relative",
            "width": "60px"
          },
          "attributes": {
            "src": "@currentField.serverRelativeUrl"
          }
        }
      ]
    },
    {
      "elmType": "img",
      "style": {
        "display": "=if([$Link]!='','none','block')",
        "background-color": "none",
        "position": "relative",
        "width": "60px"
      },
      "attributes": {
        "src": "@currentField.serverRelativeUrl"
      }
    }
  ]
}

Where Link is the internal name of my hyperlink column. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.