Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
From within my razor template, Is there anyway I can check if the following stylesheet exists before it is called?
Url.Content("~/css/my-styles.css")
There may be times when I am pulling a template over into a new instance and the stylsheet is not carried over yet, or the stylesheet may be renamed.
Thanks for any tips
Hi Blackhawk
Could this perhaps be a solution for you
https://css-tricks.com/snippets/jquery/check-if-element-exists/
Hope this helps,
/Dennis
No, that doesn't help. I would like to check if the stylesheet exist from the server side.
Does UmbracoContext.Application.Services.FileService help?
Thanks Alex. I have not used this process yet. Would you happen to know of a guide that can walk me through the use of it?
Thanks
In the razor code, you can use server.mappath to get to the directory/file, and then use system.io.file.exists on the returned path.
Nice!
I got it working like this...
@{ if (System.IO.File.Exists(HttpContext.Current.Server.MapPath("~/css/myTheme.min.css"))) { <link rel="stylesheet" href="@Url.Content("~/css/myTheme.min.css")" /> } }
Thanks a lot!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to check if stylesheet exists
From within my razor template, Is there anyway I can check if the following stylesheet exists before it is called?
There may be times when I am pulling a template over into a new instance and the stylsheet is not carried over yet, or the stylesheet may be renamed.
Thanks for any tips
Hi Blackhawk
Could this perhaps be a solution for you
https://css-tricks.com/snippets/jquery/check-if-element-exists/
Hope this helps,
/Dennis
No, that doesn't help. I would like to check if the stylesheet exist from the server side.
Does UmbracoContext.Application.Services.FileService help?
Thanks Alex. I have not used this process yet. Would you happen to know of a guide that can walk me through the use of it?
Thanks
In the razor code, you can use server.mappath to get to the directory/file, and then use system.io.file.exists on the returned path.
Nice!
I got it working like this...
Thanks a lot!
is working on a reply...