Quantcast
Channel: Microsoft Online: SharePoint Online forum
Viewing all articles
Browse latest Browse all 10096

Problem with theming root site AND web.AlternateCssUrl = web.ServerRelativeUrl

$
0
0
Hi

Not sure if this should go in the development forum or here, I'm trying to develop an app for my companies o365 SharePoint online to add a theme using the SiteLogoUrl and AlternateCSSUrl properties. I have downloaded the code and followed the video/tutorial from here https://github.com/OfficeDev/PnP/tree/master/Samples/Branding.AlternateCSSAndSiteLogo

I have published the app to my azurewebsites publishing web app and then added it to the website and the websites are now being themed successfully with the logo and css file and these are being uploaded to the site assets folders. Except I have a BIG problem with the web.ServerRelativeUrl, below is how I've pulled it from the example

                    web.AlternateCssUrl = web.ServerRelativeUrl + "/SiteAssets/contoso.css";                    web.SiteLogoUrl = web.ServerRelativeUrl + "/SiteAssets/pnp.png";



The issue is on my root site http://tenancyname.sharepoint.com the stylesheet and the image do not load, looking at the source of the homepage the stylesheet is referenced with two forward slashes so it cannot find the files:

    <link rel="stylesheet" type="text/css" href="//SiteAssets/contoso.css"/>



However going to a site collection on one of the managed paths in SharePoint online i.e. /teams/IT or /sites/Project the app works fine and the site is themed as it can find the files. Looking at the source and the stylesheet is referenced correctly:

    <link rel="stylesheet" type="text/css" href="/teams/IT/SiteAssets/contoso.css"/>



    Removing the first forward slash from the SiteAssets declaration then makes the app work in the root site but then stop working any other site collections:

                    web.AlternateCssUrl = web.ServerRelativeUrl + "SiteAssets/contoso.css";                    web.SiteLogoUrl = web.ServerRelativeUrl + "SiteAssets/pnp.png";



In any other site colections the stylesheet declaration is now (note forward slash removed between IT and SiteAssets

    <link rel="stylesheet" type="text/css" href="/teams/ITSiteAssets/contoso.css"/>



So I'm not sure what to do next to get the code to work on both the root and any other subsequent site collections, I think I need either declaration for finding the site URL or an if statement to check if it's the root site collection to then give a different alternatecssurl and sitelogourl?

Does anyone have an ideas or can write me an IF statement to check the URL?

 Thanks

Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>