Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to loop through all documents of a specific type like this
@inherits umbraco.MacroEngines.DynamicNodeContext <h2 class="header">Arkiv</h2> <ul> @{ //current month value to compare string month = String.Empty; var nodes = Model.AncestorOrSelf("Home").Descendant("NewsItem").Where("Visible"); foreach (var item in nodes) { //if the month changed to another month change month header if(!month.Equals(item.firstPublishedDate.ToString("MMMM"))) { month=item.firstPublishedDate.ToString("MMMM"); <li>@month</li> } } } </ul>
But all I get is an empty UL
This is how I would do it in XSLT
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umb="urn:umbraco.library" exclude-result-prefixes="msxml umb"> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:template match="/"> <h2 class="header">Arkiv</h2> <ul> <xsl:apply-templates select="$currentPage/ancestor-or-self::Home/descendant::NewsItem[not(umbracoNaviHide = 1)]" /> </ul> </xsl:template> <xsl:template match="NewsItem"> <li> <xsl:value-of select="firstPublishedDate"/> </li> </xsl:template> </xsl:stylesheet>
You probably need to use Descendants because I don't think your news item are on the level right beneath the homepage.
I just had a quick look at the dynamicnode cheat sheet and you have to use descendants because descendant doesn't exist
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
My first Razor code doesn't work ...
I'm trying to loop through all documents of a specific type like this
@inherits umbraco.MacroEngines.DynamicNodeContext <h2 class="header">Arkiv</h2> <ul> @{ //current month value to compare string month = String.Empty; var nodes = Model.AncestorOrSelf("Home").Descendant("NewsItem").Where("Visible"); foreach (var item in nodes) { //if the month changed to another month change month header if(!month.Equals(item.firstPublishedDate.ToString("MMMM"))) { month=item.firstPublishedDate.ToString("MMMM"); <li>@month</li> } } } </ul>
But all I get is an empty UL
This is how I would do it in XSLT
You probably need to use Descendants because I don't think your news item are on the level right beneath the homepage.
I just had a quick look at the dynamicnode cheat sheet and you have to use descendants because descendant doesn't exist
is working on a reply...