Reputation: 97
One of the Project I am working on, I have a requirement to show the site name on the document library page so that the user is aware about the site he/she is working on.
Also I want the site name to appear only on the Document Library page level. I believe if this is done at the master page level by leveraging the breadcrumb but then it would reflect everywhere in the navigation so want to make sure that it reflects only on the document library page.
Any thoughts on how to achieve this? I am working with Office 365/SharePoint online. Thanks in advance.
Upvotes: 0
Views: 90
Reputation: 1231
Code to add for updating every page where the Site Title is not displayed. (Classic UI SP 2013, 2016 and Online only) This has one more IF statement than the previous example that checks to see if the site title is already displayed.
<script>
function TTNAddSiteTitle() {
if( document.querySelector("#DeltaPlaceHolderPageTitleInTitleArea").innerText.trimRight() != ctx.SiteTitle) {
// if(ctx.listTemplate == "101" ) {
document.querySelector("#DeltaPlaceHolderPageTitleInTitleArea").insertAdjacentHTML("beforeBegin",ctx.SiteTitle + " - ");
// }
}
}
_spBodyOnLoadFunctionNames.push("TTNAddSiteTitle");
</script>
Upvotes: 1
Reputation: 1231
Several options, but most will add text to a SPAN in the page using a pattern like this:
document.querySelector("#DeltaPlaceHolderPageTitleInTitleArea span").insertAdjacentHTML("beforeBegin","Your Site Name - ")
You can have it pull the site name from the context (ctx.SiteTitle):
document.querySelector("#DeltaPlaceHolderPageTitleInTitleArea span").insertAdjacentHTML("beforeBegin",ctx.SiteTitle + " - ")
A full script block:
<script>
function TTNAddSiteTitle() {
document.querySelector("#DeltaPlaceHolderPageTitleInTitleArea").insertAdjacentHTML("beforeBegin",ctx.SiteTitle + " - ");
}
_spBodyOnLoadFunctionNames.push("TTNAddSiteTitle");
</script>
Now the question is where do you put the script...
Possible code for a master page.
<script>
function TTNAddSiteTitle() {
if(ctx.listTemplate == "101" ) {
document.querySelector("#DeltaPlaceHolderPageTitleInTitleArea").insertAdjacentHTML("beforeBegin",ctx.SiteTitle + " - ");
}
}
_spBodyOnLoadFunctionNames.push("TTNAddSiteTitle");
</script>
Upvotes: 0