Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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="<body style="background-image:url(" insertTextAfter=")">" 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.
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
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
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
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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:
I'm getting the resulting code in the source:
how do I get the image url instead of the ID. I'm using version 4.5.2.
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
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
but instead use
Cheers,
/Dirk
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
is working on a reply...