Is there a way to make a new Documenttype with 3-4 Mediapickers where i can choose images from the Media Library and then put these Images into my CSS at for example:
I don't think you can, since a css file is not a razor file. So what is left is either inline or defining the css in the page and reusing it.
If you are going to use one of the pictures on any page I would just define it on your master. Somewhere in your head where you load your other css files you can add a razorscript like the following
@{
var settingsNode = Umbraco.TypedContentAtRoot().FirstOrDefault(i => i.DocumentTypeAlias == "settings"); //Presuming you have a node with documentType "settings" at the root level
if (settingsNode != null)
{
<style>
@if (settingsNode.HasValue("backgroundpicture1")) //Check if the image has been set
{
var bgp1 = settingsNode.GetPropertyValue < IPublishedContent > ("backbackgroundpicture1");
// Only works if you have our.umbraco,corevalueconverters installed
// else use this: var bgp1 = Umbraco.TypedContent(settingsNode.GetPropertyValue("backbackgroundpicture1"));
@Html.Raw(".myclass{background-image: url(" + bgp1.Url + ");}");
}
</style>
}
}
If you are only going to use this on some pages, you can add a @RenderSection("Css", false) in this scripts place and add the script to the template page with starting with @section Css{ instead of @{
Just as an added safety check you should check to see if the media item is null. If you select an image using the media picker and then the image is later deleted from the media section, your page will throw an error. Here's a snippet showing how I do it:
Media Picker, CSS, Background URL
Hello our.Umbraco
I have a Question.
Is there a way to make a new Documenttype with 3-4 Mediapickers where i can choose images from the Media Library and then put these Images into my CSS at for example:
is there a way to do that?
I don't think you can, since a css file is not a razor file. So what is left is either inline or defining the css in the page and reusing it.
If you are going to use one of the pictures on any page I would just define it on your master. Somewhere in your head where you load your other css files you can add a razorscript like the following
If you are only going to use this on some pages, you can add a
@RenderSection("Css", false)
in this scripts place and add the script to the template page with starting with@section Css{
instead of@{
Hi Hubert,
Try to see JanĀ“s comment in this thread https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/63430-Change-background-image-in-the-CSS
Or try to see my comment in this thread: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/75454-background-images-om-template#comment-241416
Hope this helps,
/Dennis
Just as an added safety check you should check to see if the media item is null. If you select an image using the media picker and then the image is later deleted from the media section, your page will throw an error. Here's a snippet showing how I do it:
is working on a reply...