Copied to clipboard

Flag this post as spam?

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


  • Alex 18 posts 38 karma points
    Feb 25, 2010 @ 16:03
    Alex
    0

    Images Throughout site (banner images, ad images)

    Hi Guys,

    I am new here so will be interested to see how helpful the forum is!

    What i want to achieve is an are on my site (in fact two areas) that will be consistent throughout the entire site. Hard coding isnt an option because that area needs to be editable by the client.

    I have already attempted this but i dont think i was going the right way about it... The image or Advert that was consistent throughout the site i placed in my Master Template, along with other page info and a link to the Macro below. I then created a 'folder' in the node tree and in the that folder, a document called 'Offer 1' where there was the option to select an image using the Media Picker. So far so good and when i preview that page (although it does not look pretty as it isnt a 'page' as such) the image is there. As soon as i navigate away from that page the image and all the mark-up generated from the XSLT file is lost or has a Parsing Error.

    Here is the code i am using. Its snapped up from somewhere (cant remember) but is used for converting the image Node to a Url when browsed to in the media picker.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
        <xsl:variable name="mediaId" select="number($currentPage/data[@alias='mediaId'])" />
        <xsl:if test="$mediaId &gt; 0">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
            <xsl:if test="count($mediaNode/data) &gt; 0">
                <xsl:if test="string($mediaNode/data[@alias='umbracoFile']) != ''">
                    <img src="{$mediaNode/data[@alias='umbracoFile']}">
                        <xsl:if test="string($mediaNode/data[@alias='umbracoHeight']) != ''">
                            <xsl:attribute name="height">
                                <xsl:value-of select="$mediaNode/data[@alias='umbracoHeight']" />
                            </xsl:attribute>
                        </xsl:if>
                        <xsl:if test="string($mediaNode/data[@alias='umbracoWidth']) != ''">
                            <xsl:attribute name="width">
                                <xsl:value-of select="$mediaNode/data[@alias='umbracoWidth']" />
                            </xsl:attribute>
                        </xsl:if>
                        <xsl:if test="string($mediaNode/data[@alias='imgAlt']) != ''">
                            <xsl:attribute name="alt">
                                <xsl:value-of select="$mediaNode/data[@alias='imgAlt']" />
                            </xsl:attribute>
                        </xsl:if>
                    </img>
                </xsl:if>
            </xsl:if>
        </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    As i said, i am new. So take it easy on me as i am sure that there is a simple solution! Its obvious that when i navigate away from this page, the page i come to is looking for an alias 'mediaId' and not finding anything!

    Thanks in advance...

    /Alex

  • dandrayne 1138 posts 2262 karma points
    Feb 25, 2010 @ 16:23
    dandrayne
    1

    Hi Alex, and welcome to the forum!

    How does this work for you?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:variable name="mediaId" select="number($currentPage/ancestor-or-self::node/data[@alias='mediaId'])" />
    <xsl:if test="string($mediaId) != ''">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
    <xsl:if test="count($mediaNode/data) &gt; 0">
    <xsl:if test="string($mediaNode/data[@alias='umbracoFile']) != ''">
    <img src="{$mediaNode/data[@alias='umbracoFile']}">
    <xsl:if test="string($mediaNode/data[@alias='umbracoHeight']) != ''">
    <xsl:attribute name="height">
    <xsl:value-of select="$mediaNode/data[@alias='umbracoHeight']" />
    </xsl:attribute>
    </xsl:if>
    <xsl:if test="string($mediaNode/data[@alias='umbracoWidth']) != ''">
    <xsl:attribute name="width">
    <xsl:value-of select="$mediaNode/data[@alias='umbracoWidth']" />
    </xsl:attribute>
    </xsl:if>
    <xsl:if test="string($mediaNode/data[@alias='imgAlt']) != ''">
    <xsl:attribute name="alt">
    <xsl:value-of select="$mediaNode/data[@alias='imgAlt']" />
    </xsl:attribute>
    </xsl:if>
    </img>
    </xsl:if>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

     

    My changes:
    * Changed from looking at the current page to be ancestor-or-self (looks at parent page too)
    * changed the if media = 0 to be string(media) != ''

    Dan

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 25, 2010 @ 16:30
    Lee Kelleher
    1

    Hi Alex,

    Welcome to Our Umbraco forum.

    If I understand correctly, you want to have the image/media to be displayed globally across your site? (i.e. not just on a single page?)

    In your XSLT, the following line:

    <xsl:variable name="mediaId" select="number($currentPage/data[@alias='mediaId'])" />

    uses the $currentPage variable - which means that only the current page (content node) is being used.  If you want to have the same image/media-item uses across all pages, then you a way of referencing that node id in your macro.  Obviously I don't know the structure of your site right now, but if it was at homepage level, then you could try this:

    <xsl:variable name="mediaId" select="number($currentPage/ancestor-of-self::node[@level=1]/data[@alias='mediaId'])" />

    The key part here is the "ancestor-of-self::node[@level=1]" syntax.  This uses XPath to navigate up the node-set until it finds a <node> with attribute "level" that equals "1" (which is usually the homepage).

    If you knew the ID of the node (that has the image/media-item), then try this:

    <xsl:variable name="mediaId" select="number($currentPage/ancestor-of-self::node[@level=1]/descendant-or-self::node[@id=1234]/data[@alias='mediaId'])" />

    Where "1234" is your node ID.

    Hope this makes sense? Let us know if you have any questions.

    Good luck, Lee.

  • Alex 18 posts 38 karma points
    Feb 25, 2010 @ 16:59
    Alex
    0

    Well, that was fast! and plenty to choose from.

    I think specifying the node ID is the best bet! I will give this a go shortly. Thanks guys :)

  • Alex 18 posts 38 karma points
    Feb 26, 2010 @ 11:36
    Alex
    0

    Having just tried this stuff guys, its still not working.. Let me explain a little further.

    The site-tree:

    Content
    -Global Homepage
    --EN
    ---Home
    ---Next Link in main nav
    ---Next Link in main nav
    ---FOLDER (does not appear in main nav)
    ----Offer 1 (uses master template and has mediaId as a field

    Maybe this is not the best way to layout... I tried specifying directly the name of the node in the XSLT file and no luck..

    More help please!

Please Sign in or register to post replies

Write your reply to:

Draft