Copied to clipboard

Flag this post as spam?

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


  • cfrim 3 posts 23 karma points
    Apr 04, 2012 @ 20:10
    cfrim
    0

    Problem showing nodes when not all medias are picked

    Hi!

    My intention is to create a list of news, and there will be attached a thumbnail (news_teaserimage) to some of the news. The problem is that if I only pick medias in some of the nodes, I get an xslt-error, and no code will be generated. If i pick medias in all nodes, then it works.. The intention is that the code will gererate the nodes no matter if there are an image or not. If there is no image picked then it won't be displayed.

    What am I doing wrong?

    - Casper 

    <ul>

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:variable name="media" select="umbraco.library:GetMedia(news_teaserimage, 0)"/>
      
      <li>
        <h2><xsl:value-of select="@nodeName"/></h2>
        <h5><xsl:value-of select="@createDate"/></h5>
        
    <xsl:if test="news_teaserimage">
    <img src="{$media/umbracoFile}" width="70" height="70" style="float: left; padding-right: 10px; padding-bottom: 10px;" />
    </xsl:if>

          <xsl:value-of select="news_shorttext" disable-output-escaping="yes"/>
        <xsl:if test="news_largetext">
          <br />
    <style="float: left; clear: both; margin-top: -10px;" href="{umbraco.library:NiceUrl(@id)}">
          Read more
        </a>

    </xsl:if>
         
     
      </li>
    </xsl:for-each>
    </ul>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 06, 2012 @ 20:19
    Chriztian Steinmeier
    0

    Hi Casper,

    This happens because the $media variable is created regardless of the news_teaserimage having any content, and because the if test only tests the existence of the news_teaserimage, instead of testing its contents. If you move the media variable inside of the if, and re-phrase the if to test for actual content it should work:

    <ul>
        <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/*[@isDoc][not(umbracoNaviHide = 1)]">
            <li>
                <h2><xsl:value-of select="@nodeName"/></h2>
                <h5><xsl:value-of select="@createDate"/></h5>
    
                <xsl:if test="normalize-space(news_teaserimage)"> <xsl:variable name="media" select="umbraco.library:GetMedia(news_teaserimage, 0)"/> <img src="{$media/umbracoFile}" width="70" height="70" style="float: left; padding-right: 10px; padding-bottom: 10px;" /> </xsl:if>
    
                <xsl:value-of select="news_shorttext" disable-output-escaping="yes"/>
                <xsl:if test="news_largetext">
                    <br />
                    <a style="float: left; clear: both; margin-top: -10px;" href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:text>Read more</xsl:text>
                    </a>
                </xsl:if>
            </li>
        </xsl:for-each>
    </ul>

    /Chriztian 

  • cfrim 3 posts 23 karma points
    Apr 06, 2012 @ 23:49
    cfrim
    0

    Hello Chriztian,

    Thank you very much for your respons. It works perfectly! :D

     

    Thanks for your time,

     

    Casper

Please Sign in or register to post replies

Write your reply to:

Draft