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 -->
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
Post a Comment