And how do i list all the news? because usually it is $currentPage/* but would my xPath be something like /*/* then or what ? how do i list the news of all the categories and sorting them by date?
It's most likely an issue with the aliases - XPath needs the "nodeTypeAlias", not the "nodeName" - so be sure to double check that the Home and News nodes have those aliases.
i did what you wrote and tested my way on and now it is working and the problem in the end was a xsl:attribute that contained a xsl:value of that returned @urlName that somehow returned an error.
I only have a problem now with href="{umbraco.library:NiceUrl(@id)}" that it gives an error that doesn't make any sense.
i fixed the problem with the @urlName by wrapping the text inside that a with xsl:text
If you're still using my code from the beginning, you're probably seeing an error along the lines of "prefix not defined" or similar. I like to shorten the umbraco.library: prefix to just umb, so you should use this:
Also - as long as you're just outputting simple values to attributes, you can just use the curly braces instead - makes it much easier to read (and you don't have to make sure you're not outputing any text before trying to do the attribute), so:
<a>
<xsl:attribute name="href">
<xsl:value-of select="@urlName" />
</xsl:attribute>
Link
</a>
I have a problem with my list and that is that it wont get the new "news" results. It feels like it wont remove the cache, but i have tried to change something in web.config and then back, but it wont update with the new changes. The old news that is delete, is keep staying there.
Definitely sounds like a cache problem - does the old (deleted) News appear in the App_Data/Umbraco.config XML file? Does the newly created News appear in that file?
Which settings have you got on the News macro for the "Cache Period ____ Seconds" setting?
List News with category
Hello everybody. I want to list all the news order by date. The thing is that i have a Content structure that goes like this
News
-> [News Category]
-> [News Item]
How can i list all the News items order by date and inside each news item show the image of the news category.
I just want to know how to handle this - thanks
Hi Matias,
Inside a News Item (or in a for-each where the current item is a NewsItem) you can access the parent category with this:
- and then access the properties of the category as you usually do, e.g.:
(This assumes the Alias of the News Category document type is NewsCategory - change the code accordingly if it's called something else.)
/Chriztian
And how do i list all the news? because usually it is $currentPage/* but would my xPath be something like /*/* then or what ? how do i list the news of all the categories and sorting them by date?
And thanks for that! didn't knew that.
Hi Matias,
Here's a good starting point:
/Chriztian
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<xsl:variable name="newsRoot" select="$siteRoot/Home/News" />
<xsl:template match="/">
<xsl:for-each select="$newsRoot//NewsItem">
<xsl:sort select="@createDate" data-type="text" order="descending" />
<xsl:apply-templates select="." />
xsl:for-each>
xsl:template>
<xsl:template match="NewsItem">
<xsl:variable name="myCategory" select="parent::NewsCategory" />
<div class="home-news">
<div class="home-news-catimg">
<img>
<xsl:attribute name="src">
<xsl:value-of select="$myCategory/newsCategoryImg" />
xsl:attribute>
img>
div>
<a>
<xsl:attribute name="href">
<xsl:value-of select="@urlName"/>
xsl:attribute>
<h2 class="home-news-title"><xsl:value-of select="@nodeName" />h2>
a>
<div class="home-news-content">
<xsl:value-of select="newsCategoryItemContent" disable-output-escaping="yes"/>
<a class="home-news-readmore">
Read more
<xsl:attribute name="href">
<xsl:value-of select="@urlName"/>
xsl:attribute>
a>
div>
<div class="home-news-line">div>
div>
xsl:template>
xsl:stylesheet>
It doesn't show anything. I think it cant find the news items.
I have checked all the names is correct and the content tree is like this:
Content -> Home -> [News Root] -> [News Category] -> [News Item]
And again thanks for the help, i dont know what i am doing wrong...
I have also tried with $siteRoot/News
Hi Matias,
It's most likely an issue with the aliases - XPath needs the "nodeTypeAlias", not the "nodeName" - so be sure to double check that the Home and News nodes have those aliases.
/Chriztian
yes and we both aggree that it should be that Alias of the document type right?
Yes - the same goes for NewsItem and NewsCategory of course...
BTW: Which version of Umbraco are you using?
/Chriztian
I am using umbraco 4.7
OK - hardcore methods to the rescue - use this root template and let's see if the results makes sense:
If you can paste some of it (not it all - it will dump all the XML for the site), I'll have a look at what could be wrong.
/Chriztian
i did what you wrote and tested my way on and now it is working and the problem in the end was a xsl:attribute that contained a xsl:value of that returned @urlName that somehow returned an error.
I only have a problem now with href="{umbraco.library:NiceUrl(@id)}" that it gives an error that doesn't make any sense.
i fixed the problem with the @urlName by wrapping the text inside that a with xsl:text
Hi Matias,
Good to hear you've got it working.
If you're still using my code from the beginning, you're probably seeing an error along the lines of "prefix not defined" or similar. I like to shorten the umbraco.library: prefix to just umb, so you should use this:
instead...
/Chriztian
Also - as long as you're just outputting simple values to attributes, you can just use the curly braces instead - makes it much easier to read (and you don't have to make sure you're not outputing any text before trying to do the attribute), so:
Is much easier written:
/Chriztian
Thanks for the advice man! :) i am realy happy for the help! :)
I have a problem with my list and that is that it wont get the new "news" results. It feels like it wont remove the cache, but i have tried to change something in web.config and then back, but it wont update with the new changes. The old news that is delete, is keep staying there.
Definitely sounds like a cache problem - does the old (deleted) News appear in the App_Data/Umbraco.config XML file? Does the newly created News appear in that file?
Which settings have you got on the News macro for the "Cache Period ____ Seconds" setting?
/Chriztian
Yes the old news is delete in umbraco.config and the new news is there and cache periode is 0 seconds
is there anybody that have any idea about the cache problem??
is working on a reply...