I am adding a news section to my website using Razor, which filters through the news articles i've created in umbraco and displays them. This is the code that I have just now (which works fine)
What I want to do is be able to separate the newest article from the rest so I can style it differently. The rest of the news articles will have the same styling. I'm not sure if I would need to use the createdate or the articleDate property I have on the doctype to do this. Any help would be much appreciated.
I think that should be possible if you order your news items by either the articleDate or the createdDate - But I guess that the article data would make the most sense to use?
In this example I'm decklaring an integer (i) and assigning the value 0 to it and then in the foreach loop I'm checking if the value of "i" is 0 using a ternary operator. If the expression is true the "latestNews" class is added otherwise nothing is added.
In the foearch expression I have add the "OrderBy("articleDate")" - This should order the news items using the article date.
Separate Newest Article From The Rest?
Hello everyone,
I am adding a news section to my website using Razor, which filters through the news articles i've created in umbraco and displays them. This is the code that I have just now (which works fine)
What I want to do is be able to separate the newest article from the rest so I can style it differently. The rest of the news articles will have the same styling. I'm not sure if I would need to use the createdate or the articleDate property I have on the doctype to do this. Any help would be much appreciated.
Thanks!
Jedd
Hi Jedd
I think that should be possible if you order your news items by either the articleDate or the createdDate - But I guess that the article data would make the most sense to use?
So something like
In this example I'm decklaring an integer (i) and assigning the value 0 to it and then in the foreach loop I'm checking if the value of "i" is 0 using a ternary operator. If the expression is true the "latestNews" class is added otherwise nothing is added.
In the foearch expression I have add the "OrderBy("articleDate")" - This should order the news items using the article date.
I hope this makes sense and helps - And you might be able to benefit from having a look at this Razor cheatsheet https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
Hope this helps.
/Jan
Hi Jan,
Thank you for your response. I tried implementing your theory but it showed a few errors.
Not to worry though, I managed to achieve what I wanted by using the structure of my articles in Umbraco.
Thanks again!
Jedd
Hi Jedd
Good to hear you managed to find a way - Do you mind sharing the code? Others might benefit from this as well :)
Cheers, Jan
is working on a reply...