How i can change the Label for my Discussion Board App from “new discussion” to something else
-
11-12-2020 - |
Question
I am working on SharePoint online 2013. and i add a new Discussion Board App inside my Team site collection. now i name the new app as "News & Announcement", so i was expecting that the defualt link label to create new item will be changed from "new discussion" to "new news & announcements". but unfortunatly this is not the case. so now my App is labeled as "News & Announcements", while its create link is labeled as "new discussion". as follow:-
so now i tried writing the following script to override that label :-
<script>
$( document ).ready(function() {
var interval = setInterval(adjustlabel, 3000);
$('.ms-heroCommandLink span:last').text('New News & Announcments');
function adjustlabel() {
$('.ms-heroCommandLink span:last').text('New News & Announcments');
}
});
</script>
here is the markup for the link (as shown inside firefox )
side note i provide a timer because user can chose to reload the view (ajax-based request). Now the above script did not work , but when i edit my page i have noted that the link got the new label, but if i save my Page, the label will return back to "new discussion" ! so can anyone adivce on this please? why the script worked only when the page is on edit mode??
Solution
Take a look at render function within sp.ui.discussion.debug.js. You'd find two strings: Strings.STS.L_SPDiscHeroLinkAltText and Strings.STS.L_SPDiscHeroLinkFormat. You can override these string variables and use JSLink's postRender method or use the code below inside a Script Editor.
<script type="text/javascript">
//self-executing anonymous function
(function () {
// String overrides
function DiscussionListViewStringOverride() {
Strings.STS.L_SPDiscHeroLinkAltText = "add new News & Announcements";
Strings.STS.L_SPDiscHeroLinkFormat = "New News & Announcements";
}
DiscussionListViewStringOverride();
ExecuteOrDelayUntilScriptLoaded(DiscussionListViewStringOverride, "strings.js");
})();
</script>