Copied to clipboard

Flag this post as spam?

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


  • Kevin John 8 posts 28 karma points
    Oct 25, 2012 @ 19:16
    Kevin John
    0

    Errors in Razor select by document type

    Hi

    I am new to Umbraco and have a page Content structure like this:

    Home
     - Models
       - - Model 1
       - - Model 2
       - - Model 3
    About us
    Contact Us

     

    On the Home page I want to show the names and descriptions of Model 1, Model 2 and Model 3.  These three models have a document type of alias 'umbModelType'

    (Note: I think it's the alias but the doc type labels it as 'Alternative link'  - why? :) )

     

    After some searching I have tried the Razor script below but get this error:

    'Error loading MacroEngine script (file: Homepage-modellist.cshtml)'

     

     

    @inherits umbraco.MacroEngines.DynamicNodeContext


    <ul>
    @foreach (var item in @Model.AncestorOrSelf("umbModelType").Where("umbracoNaviHide != true"))   
    {

    <li>
           <h2><a href="@item.Url">@item.Name</a></h2>
           @item.modelDescription
      </li>
           
    }

    </ul>

     

    I also tried this script from another source:

    @inherits umbraco.MacroEngines.DynamicNodeContext

       // Get root node:
        var root = Model.AncestorOrSelf();

        // Get all descendants, filter by type:
        var nodes = root.Descendants("umbModelType");

        // Loop through the filtered nodes, displaying the properties:
        <ul>
        @foreach (var node in nodes)
        {
            <li>
                <h2>@node.Name</h2>
                @node.modelDescription
               
            </li>
        }
        </ul>

     

    This script above threw this error when I saved it in Umbraco:

    "error CS0103: The name 'nodes' does not exist in the current context"

     

    Any help and pointers would be much appreciated.  Thanks in advance.

    Kevin

     

Please Sign in or register to post replies

Write your reply to:

Draft