Copied to clipboard

Flag this post as spam?

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


  • René 327 posts 852 karma points
    Feb 11, 2013 @ 08:10
    René
    0

    GetMedia from different nodes

    HI every one. 

    umbraco v 4.11.3

    I have this small challenge, im sure it is quiet simple, but i cant see how

    I have this structure of my site.

     

    Each product has a media picker. It is used ti select an image presenting the category

     

    I set the image here

     

    My problem is i get the same picture on all the categories, even if i choose different images. 
    It displays only the one from the first. 

    I quiet sure i should add (@id) to the xslt on this line

    <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}"/>

    But i cant get it to work :-(

     

     

    <xsl:variable name="level" select="2"/>
    <xsl:template match="/">
        <ul id="ts-display-pf-filterable" class="image-grid">
            <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
                <li class="shapes">
                    <div class="ts-display-pf-img">
                        <a class="image" href="{umbraco.library:NiceUrl(@id)}">
                        <span class="rollover" disable-output-escaping="yes">&nbsp;</span>
                            <xsl:variable name="mediaId" select="number($currentPage/categoryImage)" />
                            <xsl:if test="$mediaId > 0">
                                <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
                                <xsl:if test="$mediaNode/umbracoFile">
                                    <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}"/>
                                </xsl:if>
                            </xsl:if>
                        </a>                          
                    </div>
                    <div class="ts-display-pf-text">
                        <h3><a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName"/>
                            </a></h3>
                        <span><xsl:value-of select="categoryTeaser" disable-output-escaping="yes"/></span>
                    </div>
                    <div class="ts-display-clear"></div>
                </li>
            </xsl:for-each>
        </ul>     
    </xsl:template>
        
  • René 327 posts 852 karma points
    Feb 11, 2013 @ 10:27
    René
    0

    Hi Again 

    I have been looking in to this and it behaves strange. 

    The reason why i get the same image on all categories is that i picks the first image on the parent node

    Here i have set the image Product on the products node

     

     

    The out put is this, it gets the image from "Products" and the text from the right nodes.

    How do i get it to pick the media from the current node and not the parent.

    Tanks for this great forum!!!!

    Kindly René

  • René 327 posts 852 karma points
    Feb 11, 2013 @ 10:55
    René
    100

     

    Hi again

    Found the error :-)

    This is the coode that works

    <xsl:variable name="mediaId" select="number(./categoryImage)" />
      <xsl:if test="$mediaId > 0">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
        <xsl:if test="$mediaNode/umbracoFile">
        <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}"/>
      </xsl:if>
    </xsl:if>

    In this line of code i needed (./categoryImage) instead of this ($currentPage/categoryImage)

    <xsl:variable name="mediaId" select="number(./categoryImage)" />

    Hope tis can help someone else

    Have a nice day 

     

  • 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