I have a website that displays News items on the homepage. The user can select which articles to display on the homepage with use of the true/false field assigned to each article.
I only want to display the first 4 articles that have this flag set to true.
I am looping using a condition which checks the position() and when it reaches 4 it breaks the loop. However, if I disable the first news item in the list, only 3 items are displayed on the home page. I assume that the position is counting the first news item and therefore when the position gets to 4 it has actually only found 3 which are active.
My code;
<xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='active']) = '1' and string(data [@alias='teaseHomepage'])='1' and position()!=4]">
<xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='active']) = '1' and string(data [@alias='teaseHomepage'])='1'][position()!=4]">
I seem to recall a similar issue fixed by putting the position() condition in it's own bracket set. Not entirely sure though :)
Also I would think you should probably use something like [position < 5], otherwise (I would think) it would keep going after the 4th and just not include the 4th.
Tom's right - moving the position() criterion to a separate predicate (square brackets ~= "filter") makes it operate on the result of the previous filter instead of being part of that filter. So the first part selects all the candidates ($documentTypeAlias, $active and $teaseHomePage) which creates kind of a temporary node-set, which you apply the position filter to afterwards to get only the 4 you want.
And yes, you will also need to use [position() < 5] to get the first 4...
Looping the first x records
I have a website that displays News items on the homepage. The user can select which articles to display on the homepage with use of the true/false field assigned to each article.
I only want to display the first 4 articles that have this flag set to true.
I am looping using a condition which checks the position() and when it reaches 4 it breaks the loop. However, if I disable the first news item in the list, only 3 items are displayed on the home page. I assume that the position is counting the first news item and therefore when the position gets to 4 it has actually only found 3 which are active.
My code;
<xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='active']) = '1' and string(data [@alias='teaseHomepage'])='1' and position()!=4]">
<div class="newsHomeHeader">
<a href="{umbraco.library:NiceUrl(@id)}"><strong><xsl:value-of select="substring(data [@alias = 'pageTitle'],1,40)"/></strong></a>
</div>
<div class="newsHomeStory">
<xsl:value-of select="substring(data [@alias = 'summary'],1,50)"/>...
</div>
</xsl:for-each>
So how do I display 4 items that have the tease flag set to true?
Just for kicks, try:
I seem to recall a similar issue fixed by putting the position() condition in it's own bracket set. Not entirely sure though :)
Also I would think you should probably use something like [position < 5], otherwise (I would think) it would keep going after the 4th and just not include the 4th.
Here is my for-each loop that I use to display the 7 latest items from an RSS feed:
Just add your flag to the for-each loop just like you would add the umbracoNaviHide.
Hope this helps,
--
Donald
Hi David,
Tom's right - moving the position() criterion to a separate predicate (square brackets ~= "filter") makes it operate on the result of the previous filter instead of being part of that filter. So the first part selects all the candidates ($documentTypeAlias, $active and $teaseHomePage) which creates kind of a temporary node-set, which you apply the position filter to afterwards to get only the 4 you want.
And yes, you will also need to use [position() < 5] to get the first 4...
/Chriztian
Thanks guys, your posts were right on the money.. I love this forum!!
is working on a reply...