Copied to clipboard

Flag this post as spam?

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


  • Sam 63 posts 126 karma points
    Aug 12, 2011 @ 13:39
    Sam
    0

    Different formatting for last news added

    Hi all,

    I have a XSLT like that 

    <div class="docCn"
      <div id="docMnu">
          <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:sort select="current()/newsdate" order="descending"/> 
      
         <li>      
           
           
           
           <href="{umbraco.library:NiceUrl(@id)}">
             <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/>&nbsp;</span>
          </a>
          
      </li>
      </xsl:for-each>
            
     </ul>
        </div>
      </div>

     

     

    Its a news listing....the client want to have a different format for the last news added...that is the top one in the list

    Do i need to put an if statement or an xsl choose ? i was thinking of using umbraco.library:DateGreaterThanOrEqualToday

    But have no idea of how to use that...

    Any help appreciated.

     

    //sam


  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 12, 2011 @ 14:11
    Tom Fulton
    0

    Hi Sam,

    Since you are sorting by date, I think you can assume the first news item is always the latest one, right?

    You can test for the position and add a class to the first item like so:

    ...
    <li>
     <xsl:if test="position() = 1"><xsl:attribute name="class">yourClass</xsl:attribute></xsl:if>
    ...

    Hope this helps,
    Tom

  • Sam 63 posts 126 karma points
    Aug 12, 2011 @ 15:02
    Sam
    0

    Tom that could be a solution .... and if i have to add extra fields for the top news like add the news summary....so the <li> should be inside the if or chose statement...am i right?

     

    //Sam

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 12, 2011 @ 15:14
    Tom Fulton
    0

    Hi Sam,

    You could simply add another if statement where you want to add your additional details:

    <div class="docCn"> 
      <div id="docMnu">
        <ul>
          <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:sort select="current()/newsdate" order="descending"/>

            <li>
              <xsl:if test="position() = 1"><xsl:attribute name="class">yourClass</xsl:attribute></xsl:if>
          
              <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/>&nbsp;</span>
              </a>

              <xsl:if test="position() = 1">
            News Summary:  <xsl:value-of select="newssummary"/>
            Other info...
          </xsl:if>
         
            </li>
          </xsl:for-each>

        </ul>
      </div>
    </div>

    Also here's another way to do it using the match-templates approach.  Could be refactored even further if you like but this is the basic idea.  This way depending on how different the first news item layout is, you don't need to have a bunch of IF statements.

    <div class="docCn"> 
      <div id="docMnu">
        <ul>
          <xsl:apply-templates select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']" />
        </ul>
      </div>
    </div>

    <xsl:template match="NewsDocTypeAlias [position() = 1]">
      <li class="yourClass">
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/>&nbsp;</span>
        </a>
        Summary:  <xsl:value-of select="newssummary"/>
      </li>
    </xsl:template>

    <xsl:template match="NewsDocTypeAlias [position() &gt; 1]">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/>&nbsp;</span>
        </a>
      </li>
    </xsl:template>

    Hope this helps,
    Tom

  • Sam 63 posts 126 karma points
    Aug 15, 2011 @ 09:53
    Sam
    0

    Tom,

    Back to work...yeah finally get it to work using xsl:choose.

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:sort select="current()/newsdate" order="descending"/> 

            <li>
              <xsl:if test="position() = 1"><xsl:attribute name="class">feature</xsl:attribute></xsl:if>
              <href="{umbraco.library:NiceUrl(@id)}">
              
              <xsl:choose>        
                  <xsl:when test="position() = 1">
                   
                 <div class="divfeature">
                  
                     

                    
                     
                    
                       <div class="divfeature-title"><xsl:value-of select="newstitle"/></div>
                       <div class="divfeature-date"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/></div>
                       <div class="divfeature-summ"><xsl:value-of select="umbraco.library:TruncateString(newsummary, 180, '...')" disable-output-escaping="yes"/></div>
                                      
                 </div

                 </xsl:when>
                
               <xsl:otherwise
                <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/> </span>
             </xsl:otherwise>
              
           </xsl:choose>
                </a>
            </li>
            
          </xsl:for-each>

    Thks to you...put me on the track...I have another question though...my news item is linked to a gallery in media section...how can i retrive the first image in the media folder to show on the news linsting....

    My idea : test if there a link to a gallery...then retrive the first image and published...Ive written something like this:

    <xsl:variable name="source" select="/macro/source"/>
    <xsl:variable name="mediapickerproperty" select="$currentPage/linkToGallery"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
     <div class="docCn"
      <div id="docMnu">
        <ul>
          <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:sort select="current()/newsdate" order="descending"/> 

            <li>
              <xsl:if test="position() = 1"><xsl:attribute name="class">feature</xsl:attribute></xsl:if>
              <href="{umbraco.library:NiceUrl(@id)}">
              
              <xsl:choose>        
                  <xsl:when test="position() = 1">
                   
                 <div class="divfeature">
                  
                     
                       <div class="divfeature-image">
                         <img>
                            <xsl:attribute name="src">
                            <xsl:value-of select="umbraco.library:Replace(umbraco.library:GetMedia(@id, 0)/umbracoFile, '.', '_thumb.')"/>            
                            </xsl:attribute>
                         </img>               
                      </div>
                    
                     
                    
                       <div class="divfeature-title"><xsl:value-of select="newstitle"/></div>
                       <div class="divfeature-date"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/></div>
                       <div class="divfeature-summ"><xsl:value-of select="umbraco.library:TruncateString(newsummary, 180, '...')" disable-output-escaping="yes"/></div>
                                      
                 </div

                 </xsl:when>
                
               <xsl:otherwise
                <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/> </span>
             </xsl:otherwise>
              
           </xsl:choose>
                </a>
            </li>
            
          </xsl:for-each>

        </ul>
      </div>
    </div>
     
    </xsl:template>

     

    But somehow i know im missing some for-each stuff (  <xsl:for-each select="umbraco.library:GetMedia($mediapickerproperty, 1 ) but don't know exactly how to call that....

    For now my code renders no-image at all..

     

    Any idea....

    Thks

    /Sam

     


  • Sam 63 posts 126 karma points
    Aug 15, 2011 @ 09:55
    Sam
    0

    EDIT:

    Right code below ...forgot to put the if statement for media picker 

    <xsl:variable name="source" select="/macro/source"/>
    <xsl:variable name="mediapickerproperty" select="$currentPage/linkToGallery"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
     <div class="docCn"
      <div id="docMnu">
        <ul>
          <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:sort select="current()/newsdate" order="descending"/> 

            <li>
              <xsl:if test="position() = 1"><xsl:attribute name="class">feature</xsl:attribute></xsl:if>
              <href="{umbraco.library:NiceUrl(@id)}">
              
              <xsl:choose>        
                  <xsl:when test="position() = 1">
                   
                 <div class="divfeature">
                  
                     <xsl:if test="$mediapickerproperty &gt; 0">
                       <div class="divfeature-image">
                         <img>
                            <xsl:attribute name="src">
                            <xsl:value-of select="umbraco.library:Replace(umbraco.library:GetMedia(@id, 0)/umbracoFile, '.', '_thumb.')"/>            
                            </xsl:attribute>
                         </img>               
                      </div>
                    </xsl:if>
                     
                    
                       <div class="divfeature-title"><xsl:value-of select="newstitle"/></div>
                       <div class="divfeature-date"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/></div>
                       <div class="divfeature-summ"><xsl:value-of select="umbraco.library:TruncateString(newsummary, 180, '...')" disable-output-escaping="yes"/></div>
                                      
                 </div

                 </xsl:when>
                
               <xsl:otherwise
                <xsl:value-of select="newstitle"/><br/><span class="size"><xsl:value-of select="umbraco.library:FormatDateTime(./newsdate, 'd MMMM, yyyy')" disable-output-escaping="yes"/> </span>
             </xsl:otherwise>
              
           </xsl:choose>
                </a>
            </li>
            
          </xsl:for-each>

        </ul>
      </div>
    </div>
      
      



    </xsl:template>

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 15, 2011 @ 13:50
    Tom Fulton
    0

    It looks like you are passing in the ID of the News node instead of the media picker property to the GetMedia call.

    Try:

                        <xsl:value-of select="umbraco.library:Replace(umbraco.library:GetMedia($mediapickerproperty, 0)/umbracoFile, '.', '_thumb.')"/>      

    -Tom

     

  • Sam 63 posts 126 karma points
    Aug 17, 2011 @ 09:47
    Sam
    0

    Tom , got it to work...my first error was that as was picking a folder instead of an image ....

    I used that code :  <img src="{concat(substring-before(umbraco.library:GetMedia(newsPreview, 'true'),'.'),'_thumb.jpg')}" />

    where newsPreview is the alias in the document type for media picker.

    Thks buddy.

    //Sam

Please Sign in or register to post replies

Write your reply to:

Draft