Copied to clipboard

Flag this post as spam?

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


  • Robin Hansen 135 posts 368 karma points
    Oct 26, 2010 @ 10:10
    Robin Hansen
    0

    Can't loop images from subpages

    I'v created an xslt file from the the standard template "List Sub Pages From Current Pages" and it works perfect all in all - however I'm facing a delicate problem. The nodenames from the subpages loops perfectly file but the images don't. On the subpages I've contenttext and images(choosen bu the imagepicker property).

    My code looks like this:
  • Robin Hansen 135 posts 368 karma points
    Oct 26, 2010 @ 10:21
    Robin Hansen
    0

    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:sort select="@createDate" order="descending"/>
    <xsl:if test="position() &gt; $itemsPerPage * number($pageNumber -1) and position() &lt;= number($itemsPerPage * number($pageNumber -1) + $itemsPerPage)">
    <img src="{concat(substring-before(umbraco.library:GetMedia($currentPage/* [@isDoc]/newsImage, 'false')/umbracoFile,'.'), '_thumb.jpg')}" alt="{@nodeName}" align="left"/>
    <h2>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </h2>
    </xsl:if>

  • Rik Helsen 670 posts 873 karma points
    Oct 26, 2010 @ 10:35
    Rik Helsen
    0

    what output do you have?

  • Rik Helsen 670 posts 873 karma points
    Oct 26, 2010 @ 10:37
    Rik Helsen
    0

    Why are you using

    $currentPage/*

    inside the foreach loop? you want to use the current item i believe?

    try this:

     src="{concat(substring-before(umbraco.library:GetMedia(umbraco.library:GetMedia(ImageProperty,'false')/*/data[@alias = 'umbracoFile']), '_thumb.jpg')}" alt="{@nodeName}" align="left"/>


     

    replace ImageProperty by the alias of the image

  • Robin Hansen 135 posts 368 karma points
    Oct 26, 2010 @ 10:38
    Robin Hansen
    0

    As mentioned the nodenames loops fine but all images are the same - actually it's the latest updated image which repeats itself instead of looping... :-/

  • Rik Helsen 670 posts 873 karma points
    Oct 26, 2010 @ 10:40
    Rik Helsen
    0

    try the updated code sample i pasted above, inside the foreach loop, you shouldn't be using $currentpage again, as this doesn't reflect the current item in the foreach loop, in instead the same current page as always...

     

     

  • Robin Hansen 135 posts 368 karma points
    Oct 26, 2010 @ 10:53
    Robin Hansen
    0

    I hate to say it but I dont get any output from this line - only this wellknown message: Error reading XSLT.... :-(

    By ImageProperty I suppose you mean newsImage whics is the name of my ImagePicker property...

    I use Umbraco 4_5_2 for ASP.NET 3.5 by the way...

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 26, 2010 @ 11:03
    Kim Andersen
    0

    Hi Robin

    Try this code out:

    <xsl:if test="./newsImage !=''">
       
    <img
    src="{concat(substring-before(umbraco.library:GetMedia(./newsImage, 0)/umbracoFile,'.'), '_thumb.jpg')}" alt="{@nodeName}" align="left"/>
    </xsl:if>
    <h2>
       <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
       </a>
    </h2>

    The code might fail if some of the nodes has an empty newsImage property. Then the GetMedia extension will fail for sure.

    /Kim A

  • Robin Hansen 135 posts 368 karma points
    Oct 26, 2010 @ 11:08
    Robin Hansen
    0

    I would'nt worry about that because the image picker property has a Mandatory=true attribute so I cannot publish a new note without an image... - but thanks for the code snippet - worked perfectly... tmx m8

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 26, 2010 @ 11:13
    Kim Andersen
    0

    Great to hear that it worked out Robin. Even though the property is mandatory, it's a nice way of debugging theese kinds of things. And maybe some day something goes wrong in the publishing or something like that - in those cases it's nice to have made some "bulletproof" code that won't break :)

    But glad you got it working :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft