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...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
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...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.