Copied to clipboard

Flag this post as spam?

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


  • Aximili 177 posts 278 karma points
    Jun 29, 2011 @ 08:39
    Aximili
    0

    How do you output a field in head > style

    I have a field called "background" - for a page background.

    In the template I am trying to do this:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Master.master" AutoEventWireup="true" %>

    <asp:content ContentPlaceHolderId="cphHead" runat="server">
    <style type="text/css">
    #content {
    background: url('<%=VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />)%>');
    }
    </style>
    </asp:content>

    But it doesn't like it. Anyone know how do to this?

  • Kim Andersen 1447 posts 2197 karma points MVP
    Jun 29, 2011 @ 08:41
    Kim Andersen
    0

    Hi Hardi

    The background property is this a upload field?

    Could you try this snippet:

    <%@MasterLanguage="C#"MasterPageFile="/masterpages/Master.master"AutoEventWireup="true" %>

    <asp:content ContentPlaceHolderId="cphHead"runat="server">
     
    <styletype="text/css">
       
    #content {
          background
    : url(<umbraco:Item field="background" runat="server" />);
       
    }
     
    </style>
    </asp:content>

    /Kim A

  • Aximili 177 posts 278 karma points
    Jun 29, 2011 @ 08:48
    Aximili
    0

    Yes, thanks Kim, sorry forgot to mention it is an Upload field.

    Your code produces this

    background: url(~/media/15/about-cooper-street.jpg);

    How do I fix the tilde ~ ? Thanks!

  • Aximili 177 posts 278 karma points
    Jun 30, 2011 @ 03:15
    Aximili
    0

    Here is the solution

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Master.master" AutoEventWireup="true" %>
    <%@ Import Namespace="umbraco" %>
    <%@ Import Namespace="umbraco.presentation" %>
    <%@ Import Namespace="umbraco.presentation.nodeFactory" %>

    <asp:content ContentPlaceHolderId="cphHead" runat="server">
    <style type="text/css">
    #content {
    background-image: url('<%=VirtualPathUtility.ToAbsolute(Node.GetCurrent().GetProperty("background").Value)%>');
    }
    </style>
    </asp:content>
  • 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.

Please Sign in or register to post replies