|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
OK, here we go. This is so common task that I was surprised to find that it's not in the videos. I want to have a top news macro. I have a page called 'News' of document type with alias 'newsArea'. I have several news as subpages and their document type is 'newsItem'. I want to have a macro that will display top three (or whatever number) of news on any page i put it. In another post I saw similar thing and tried the following in my 'for' loop
<xsl:for-each select="$currentPage/descendant::node [@nodeTypeAlias = 'newsArea']/node"> <xsl:sort select="./data[@alias='articleDate']" order="descending"/> <xsl:if test="position() <= $numberOfItems">
<a title="Read news item: {@nodeName}" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/></a> <br/> <xsl:value-of select="umbraco.library:LongDate(./data[@alias='articleDate'])"/>
</xsl:if> </xsl:for-each>
It didn't work so as instructed in the same thread I substituted with
$currentPage/ancestor-or-self::node[@level = '1']/node[@nodeName='News']/descendant::node[@nodeTypeAlias='newsArea']
still a no go. Would you, please help me with that. Also I would like to have an attribute in my newsItem called 'important' that would mark if the item should appear on this control. So basically I want to select the top 3 'newsItem's marked as important.
|
|
 Rank: Addict
Joined: 2/19/2007 Posts: 824 Location: Belgium
|
Hi Martin, Maybe this article can help you out: http://www.nibble.be/?p=15
Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
Hi Tim,
Thanks for the reply but the macro still generates nothing.
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
hi, Have you checked the nodeTypeAlias, 'cause I'm thinking you've got the wrong one in place? Code:$currentPage/ancestor-or-self::node[@level = '1']/node[@nodeName='News']/descendant::node[@nodeTypeAlias='newsArea']
$currentPage/ancestor-or-self::node[@level = '1']/node[@nodeName='News']/descendant::node[@nodeTypeAlias='newsItem'] Btw, I personally think it's a bad idea to use @nodeName. If anyone changes the name of the node, you 're up for a pretty annoying debug session to find out why? If you need to check for an extra property important, you'll need to add something such as Code:string(/data [@important]) = '1' Hope that helps. Regards, /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
Hi Dirk,
Thanks for the correction. That was probably one reason but there must be another one because it is still not working. I'm completely new to XLS and have very basic idea of what I'm doing. If there is a better way than using @nodeName please post it. I just saw this as an example and started from there.
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
Hi, Let's try the most obvious first. As I can't see the complete xslt, I'd advice to do the following: - Replace the current for-each with: Code:<xsl:for-each select="umbraco.library:GetXmlNodeById(id)"> <a title="Read news item: {@nodeName}" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </xsl:for-each> - Replace in the for-each construct id with the id of 'News' node (Node that has child nodes of type 'newsItem'. If you don't know its id, hover over the node in the Content section and look at the left bottom javascript construct. Id between () is the node id. - Don't worry about the rest, we'll work that out later on... Do you get any output then? And you've already used a better way than @nodeName, @nodeTypeAlias that is! Looking forward to the answer. /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
ok, this might be a stupid question but how do I find the ID of the node?
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
Hmm, It's a stu...no, as mentioned in previous post... Quote:If you don't know its id, hover over the node in the Content section and look at the left bottom javascript construct. Number between () is the node id. Regards, /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
Sorry for the stupid question. I overlooked that part. Here is the output after I put the id of the News page Code: <a title="Read item: News" href="/news.apsx">News</a>
|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
maybe you meant Code: <xsl:for-each select="umbraco.library:GetXmlNodeById(id)/node">
in wich case the rendered html is exactly the required result
|
|
 Rank: Umbracoholic
Joined: 9/27/2007 Posts: 1,123 Location: Belgium
|
Great, if that works, gradually change things until you get the desired result. Remember, always change small things, so you know when something goes wrong where to look for... Good luck. Regards, /Dirk
level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
|
|
Rank: Enthusiast
Joined: 10/27/2008 Posts: 32 Location: Bulgaria
|
Ok, I figured where the problem might be. In Dirk's example source I substituted select="@nodeName" with select="@nodeTypeAlias" and it returned 'News Item' wich is the name of the document type and not the alias. The alias is 'newsItem'. I doublechecked on this. Also the for the News page it returnes 'News Area' and not 'newsArea'. How did that happen? From that point on it was easy given the examples in this and other threads. But is this a bug in umbraco? my version is 3.0.6
Thanks to Dirk for the patient and comprehensive response
|
|
|
Guest |