Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 281 posts 605 karma points c-trib
    Oct 09, 2010 @ 01:31
    ianhoughton
    0

    Dynamic body background image

    I would like to be able to change the background image on each page the user creates. I have add a media picker to the page datatype.

    I've added the following code to the masterpage template:

    <umbraco:Item field="backgroundImage" insertTextBefore="&lt;body style=&quot;background-image:url(" insertTextAfter=")&quot;&gt;" runat="server" />

    I'm getting the resulting code in the source:

    <body style="background-image:url(1055)">

    how do I get the image url instead of the ID. I'm using version 4.5.2.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Oct 09, 2010 @ 02:30
    bob baty-barr
    0

    here is a post regarding getMedia() in inline xslt plus a generic getMedia() in a macro...

    both use imageGen for sizing, but you will get the idea.

    http://our.umbraco.org/forum/developers/xslt/4537-Using-Imagegen-in-inline-xslt

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 09, 2010 @ 10:50
    Dirk De Grave
    0

    Maybe already know this but ust in case you're using a v4.5.x version: be aware that the example from the link Bob provided is still in old xml syntax, so no more 

    umbraco.library:GetMedia($imageNode,0)/data [@alias = 'umbracoFile']

    but instead use

    umbraco.library:GetMedia($imageNode,0)/umbracoFile

     

    Cheers,

    /Dirk

  • ianhoughton 281 posts 605 karma points c-trib
    Nov 29, 2010 @ 18:00
    ianhoughton
    0

    This is how I  accomplished it in the end:

    <xsl:param name="currentPage"/>
    <xsl:variable name="imageRoot" select="$currentPage/bodyImage"/>
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/bodyImage, 1)/umbracoFile" />    
        
    <xsl:variable name="BodyTagStart" select="concat('<body style="background-image:url(',$media,')" ')"/>
    <xsl:variable name="BodyTagEnd" select="concat(class,'>')"/>    
        
    <xsl:template match="/">

    <xsl:value-of select="concat($BodyTagStart,$BodyTagEnd)" disable-output-escaping="yes"/>
      
    xsl:template>

    I then replaced the body tag in the master template with the macro:

    <umbraco:Macro Alias="BodyTag" runat="server"></umbraco:Macro>

    and created a "required" background picker on each text page

Please Sign in or register to post replies

Write your reply to:

Draft