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?
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.
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:
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....
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>
<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"/> </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
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:
Hope this helps,
Tom
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
Hi Sam,
You could simply add another if statement where you want to add your additional details:
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.
Hope this helps,
Tom
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>
<a 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>
<a 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
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>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:choose>
<xsl:when test="position() = 1">
<div class="divfeature">
<xsl:if test="$mediapickerproperty > 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>
It looks like you are passing in the ID of the News node instead of the media picker property to the GetMedia call.
Try:
-Tom
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
is working on a reply...