View formatting on Document Library in Sharepoint Online
-
08-02-2021 - |
Question
I'm looking to format the Site pages view using JSON Formatting. Is there a way to get the Published date field and also the page URL?
I see there is no column formatting on Name field on a library, but looking if there is a tweak to fetch the page url.
Solution
You can get the URL of Site page using [$FileRef]
. This will be relative URL of page like:
sites/SiteName/SitePages/PageName.aspx
I was not able to find how to get the Published date field. But you can get the Created and Modified date using [$Created]
and [$Modified]
respectively.
You can use below JSON code on any field. It will show the current column value and on-click will redirect you respective to Site Page.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField",
"attributes": {
"href": "[$FileRef]"
}
}
References:
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange