Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sebastian Dammark 583 posts 1407 karma points
    Dec 21, 2011 @ 15:35
    Sebastian Dammark
    0

    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

    <?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>
    
    Any ideas ?
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Dec 21, 2011 @ 15:56
    Dave Woestenborghs
    0

    You probably need to use Descendants because I don't think your news item are on the level right beneath the homepage.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Dec 21, 2011 @ 15:58
    Dave Woestenborghs
    1

    I just had a quick look at the dynamicnode cheat sheet and you have to use descendants because descendant doesn't exist

Please Sign in or register to post replies

Write your reply to:

Draft