20

I'm using SharePoint 2013 and I have created master page file (as .html) and converted it to .master file. As I have read, I should only modify html file, because all changes will be also registered in .master file and this doesn't work in opposite way.

I have also read, that I should keep css files and images in style library. The problem is, that all tutorials say that, but just for example, they are keeping those files in Master Pages folder. So I'm using:

<!--SPM:<SharePoint:CssRegistration Name="<% $SPUrl=~sitecollection/Style Library/MyCustomTheme/mycss.css%>" runat="server" After="corev15.css"/>-->

And this causes a problem on site: "An error occurred during translation of your HTML master page. For more information, please navigate to the master page by clicking the preview button in the Master Page Gallery or directly typing its URL".

If I'm not using SPUrl, but instead just a direct link to file, everything works fine, so there is no problem with CssRegistration - I don't know what's the issue here?

I also need to pack my custom design to .wsp file. When keeping all stuff in Master Pages folder, it can by done by Design Manager (automatically packs what's needed). If I keep some files in Style Library, will the Design Manager also pack them to solution?

3 Answers 3

16

This issue caused by angle brackets "<" to fix it replace it with "&lt" as below:

<!--SPM:<SharePoint:CssRegistration name="&lt;% $SPUrl:~sitecollection/_catalogs/masterpage/css/style.css %&gt;" runat="server"  />-->
7
  • This is incorrect, the brackets and percents identifies an inline asp.net code! Commented May 1, 2013 at 13:42
  • @RobertLindgren Have you tried?
    – Shannak
    Commented Sep 22, 2013 at 17:25
  • Multiple times. Commented Sep 22, 2013 at 17:29
  • 1
    @RobertLindgren, Anyway, I faced this issue before and i tried this solution (replace "<" with "&lt") , and it's work with me without any issues.
    – Shannak
    Commented Sep 24, 2013 at 16:00
  • 2
    Agree, this is the correct answer. Tested and confirmed by myself Commented May 17, 2014 at 6:44
3

i dont think your doing it properly!

<SharePoint:CssRegistration Name="<%$SPrl:~sitecollection/Style Library/MyCustomTheme/mycss.css%>" runat="server" After="corev15.css"/>

you were doing "<% $SPUrl=~ instead of "<%$SPrl:~

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.cssregistration.aspx

EDIT

try

<SharePoint:CssRegistration Name="<% $SPUrl:~SiteCollection/Style Library/Core Styles/mycss.css%>" runat="server"/>

after digging around i found that most examples are storing their css in the core styles folder, i dont know why but they are, maybe you can add your custom folder to that folder. also you dont need After="corev15.css", well spotted loool I didnt notice the typo loooool, also make sure when you add the css to the hive folder that it has the correct permissions on the file and that you do an iisreset

so it would look like this if you add the folder:

<SharePoint:CssRegistration Name="<% $SPUrl:~SiteCollection/Style Library/Core Styles/MyCustomTheme/mycss.css%>" runat="server"/>
4
  • Sorry, I have made a typo there. I'm not using the sign of equality. But with spaces I have tried all combinations, because I have seen over the web all variations, as in: here or here. Obviously, there is a typo on msdn too, because it should be "SPUrl" not "SPrl". And as I said: I tried all combinations, even with "SPrl". Commented Mar 4, 2013 at 9:33
  • ammended my answer
    – Ali Jafer
    Commented Mar 4, 2013 at 9:46
  • Unfortunately, nothing of above works. I have also tried adding "~language" to expression and putting my file in "en-us" folder, but the error is the same. I have played with permissions, but also nothing helps. Commented Mar 4, 2013 at 15:57
  • You will need the "After" attribute if you are overriding styles in the core CSS. This allows you to have your CSS rendered after the css file mentioned. You don't need to include the After attribute if your style rules are more specific, however. Commented Oct 24, 2016 at 17:16
1

This works fine for me, in the html master file :

<!--SPM:<SharePoint:CssRegistration ID="CustomCSS" name="&#60;% $SPUrl:~SiteCollection/_catalogs/masterpage/css/custom.css%&#62;" After="corev15.css" runat="server"/>-->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.