Using an external file in a master page

In our setup, there are frequent changes that get requested that should apply to all sites.
As these sites cross site collections, each one has a custom master page although it's the same master page for all sites.


In order to make these changes easier, I created a .js file containing document.writes to display my HTML code:


document.write('<div class="SiteTitle"><a href="/">(Acronym for title which will change next week)</a></div>');


Any HTML code can go in there, but SharePoint code like this cannot:
<SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/">
<SharePoint:SiteLogoImage  LogoImageUrl="http://sharepoint.name/SiteAssets/MasterPage%20Assets/sitelogoimage.png" runat="server"/>
 </SharePoint:SPLinkButton>
The SharePoint tags are executed server side while the js is client side code.
However, in the example above, changine the image in the one spot will change it throughout anyway.


Inside the master page, just add a reference to the js file
<!-- Site Name -->
<script type="text/javascript" src="http://sharepoint.name/Style%20Library/SiteName.js"></script>
<!-- Site Name -->







Comments

Popular posts from this blog

Setting SharePoint announcements to auto delete after expiration

Updating a single field in a SharePoint List using Power Automate Flows

SharePoint driven rich text dashboard using jqueryui. (JQuery file)