Copied to clipboard

Flag this post as spam?

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


  • Jan 54 posts 74 karma points
    Jul 02, 2010 @ 10:44
    Jan
    0

    Place a macro inside a style=""

    hello i need to place a macro inside the <body style=" background-image:--here--; ">

    or is there another way to set a style for the body tag within the macro itself? and then just have the macro on the page?

    this is to be used with a random picture macro so the background image changes when ever the page is loaded.


  • Rik Helsen 670 posts 873 karma points
    Jul 02, 2010 @ 11:00
    Rik Helsen
    0

    Can't you generate the entire opening body tag with the macro?

    Alternatively just make your macro generate inline css that assigns the background image to the body tag or a div if your choice.

     

     

  • Dan 1288 posts 3921 karma points c-trib
    Jul 02, 2010 @ 11:01
    Dan
    0

    You could get your macro to write out an embedded style sheet segment e.g.

    <style type="text/css">
    body {
    background-image: url(img/whatever.png);
    }
    </style>

    Then just place the macro in your <head></head> section in the template.

    Or you could indeed just include the macro inside the <body> tag directly, writing out just the name of the image.  Down to personal preference really, but the former option is more flexible.

  • Dan 1288 posts 3921 karma points c-trib
    Jul 02, 2010 @ 11:04
    Dan
    0

    Just a tip... if you put your macro inside a quoted attribute, make sure your macro parameters use single quotes.  e.g.

    <body style="background: url(<umbraco:Macro Alias='backgroundImage' runat='server'></umbraco:Macro>);">
  • Jan 54 posts 74 karma points
    Jul 02, 2010 @ 11:14
    Jan
    0

    thanx that worked put the code like this and placed the macro inside the header

    should have thought of that :P

    <xsl:param name="currentPage"/>
    <!-- write the media folders id number here to point to the correct folder -->
    <xsl:variable name="bannerFolder" select="1338"/>

    <xsl:template match="/">
        <xsl:variable name="numNodes" select="count(umbraco.library:GetMedia($bannerFolder, 1)/node)"/>
        <xsl:variable name="random" select="floor(Exslt.ExsltMath:random() * $numNodes) + 1"/>

    <style type="text/css">
        body {
            background-image: url(<xsl:value-of select="umbraco.library:GetMedia($bannerFolder, 1)/node [position() = $random]/data"/>);
        }
    </style>

    </xsl:template>

Please Sign in or register to post replies

Write your reply to:

Draft