Adding dynamic CSS link to Sharepoint MasterPage

In a situation where you have to load CSS files based on the current culture, in this situation you have to use the ~language variable in SharePoint. This will retrieve the proper language ID(example for English-US: en-US, Arabic-SA: ar-SA).

<link rel="stylesheet" href="<%$SPUrl:~sitecollection/_catalogs/masterpage/en-us/css/mystyle.css %>" />

In your master page HTML layout you can add the snippet as below:

<!--SPM:<asp:Literal runat="server" Text="<link rel='stylesheet' href='"/>-->
        <!--SPM:<asp:Literal runat="server" Text="<% $SPUrl:~sitecollection/_catalogs/masterpage/~language/css/mystyle.css %>"/>-->
        <!--SPM:<asp:Literal runat="server" Text="' type='stylesheet' />"/>-->

When using CSSRegistration can use the following snippet:

expected link URL :

<SharePoint:CssRegistration name=”<% $SPUrl:/_layouts/projectname/styles/~language/master.css %>” runat=”server”/>

Master page html page :

<!--SPM:<SharePoint:CssRegistration name="&lt;% $SPUrl:~site/_catalogs/masterpage/test/style.css %&gt;" runat="server" after="SharepointCssFile" />-->
<!--SPM:<SharePoint:CssRegistration name="&lt;% $SPUrl:~site/_catalogs/masterpage/test/style.css %&gt;" runat="server" after="SharepointCssFile" />-->

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: