Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kate 267 posts 610 karma points
    Feb 27, 2016 @ 09:06
    Kate
    0

    Background images om template

    Hi I would like to add a background image to my template. Because I want to create background images on various templates, I would like to use a Macro. In my document type I have a propertie = addBgImage, Type = Media Picker.

    I would also like to test if the user have added a images on the page.

    What I have so fare is this:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{ if (CurrentPage.HasValue("addBgImage")){ 
            var urlImages = Umbraco.Media(CurrentPage.addBgImage).Url;
            style="background:url(@urlImages);"
            } 
         }
    

    Hope that you can help me :-)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 27, 2016 @ 09:12
    Dennis Aaen
    1

    Hi Kate,

    What if you do something like this

    @{ if (CurrentPage.HasValue("addBgImage")){ 
            var urlImages = Umbraco.Media(CurrentPage.addBgImage);
            style="background:url(@urlImages.umbracoFile);"
            } 
         }
    

    Hope this helps,

    /Dennis

  • Kate 267 posts 610 karma points
    Feb 27, 2016 @ 09:18
    Kate
    0

    It did not work This is what I get ind the html code

    <div id="cntEmployee" class="cntSubpageContainer" Error loading Partial View script (file: ~/Views/MacroPartials/BackgroundImages.cshtml) >
    
  • Kate 267 posts 610 karma points
    Feb 27, 2016 @ 09:21
    Kate
    0

    when I write it like this:

    @{ if (CurrentPage.HasValue("addBgImage")){ 
            var urlImages = Umbraco.Media(CurrentPage.addBgImage).Url;
            <div id="cntEmployee" class="cntSubpageContainer" style="background:url(@urlImages);">nnn</div>
            } 
         }
    

    it works fine. But I want to be able to just use the style="background:url(...);"

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 27, 2016 @ 09:32
    Dennis Aaen
    100

    Hi Kate,

    Try this:

     @{ 
               if (CurrentPage.HasValue("addBgImage")){ 
                  var urlImages = Umbraco.Media(CurrentPage.addBgImage); 
              <style>
                        #cntEmployee{
                             background:url(@urlImages.umbracoFile) no-repeat;
                        }
                </style>
             } 
       }
    

    Hope this helps,

    /Dennis

  • Kate 267 posts 610 karma points
    Feb 27, 2016 @ 09:38
    Kate
    0

    Thanks Dennis

    It works perfect :-)

Please Sign in or register to post replies

Write your reply to:

Draft