更改新式 SharePoint Online 列表表单中的“新项目”文本
要求:更改新式 SharePoint Online 列表中的“新项目”文本。
如何更改 SharePoint Online 中的新项目文本?
默认情况下,当您在 SharePoint Online 列表中创建新项目时,“新建项目”面板将“新项目”作为窗格的标题。如果您想将此文本更改为相关内容怎么办?例如。在“项目”列表中,显示“创建新项目”而不是“新项目”不是很好吗?那么,以下是通过格式化列表表单布局来更改新项目窗格标题的步骤:
- 导航到您的现代 SharePoint Online 列表 >> 单击“新建”。这将在现代列表中打开新项目面板。
在“新建项目”窗格中,单击“编辑表单”下拉列表并选择“配置布局”。
在“将格式应用到”下拉列表中,选择“标头”,然后在“格式代码”中输入以下 JSON 代码。
{
"elmType": "div",
"style": {
"font-size": "18px",
"font-weight": "600"
},
"txtContent": "Create New Project"
}
预览并保存您的更改。这会将列表表单布局设置为给定的 JSON 格式。有关列表表单格式的更多信息:https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/list-form-configuration
PnP PowerShell 配置新项目表单布局
使用此 PowerShell 为 SharePoint Online 列表中的新项目表单设置布局 JSON:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName="Projects"
$JSON = @"
{
"headerJSONFormatter":
{
"elmType": "div",
"style": {
"font-size": "18px",
"font-weight": "600"
},
"txtContent": "Create New Project"
}
}
"@
#Connect to the site
Connect-PnPOnline -Url $SiteURL -Interactive
#Apply JSON Formatting to the content type
$ContentType = Get-PnPContentType -Identity "Item" -List $ListName
$ContentType.ClientFormCustomFormatter = $JSON
$ContentType.Update($False)
Invoke-PnPQuery
我在这里使用了“headerJSONFormatter”属性。同样,您也可以使用“footerJSONFormatter”或“bodyJSONFormatter”属性。以下是来自社区的一些示例:https://github.com/pnp/List-Formatting/tree/master/form-samples

