Copied to clipboard

Flag this post as spam?

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


  • Stephen Davidson 216 posts 392 karma points
    Dec 11, 2012 @ 17:59
    Stephen Davidson
    0

    Pull bodyText content from page by Document Type

    Still getting to grips with Razor...I want to display the copy from my solutions page on the home page, I have a structure like this.

    Home
    --------Solutions
    ---------------------Solution

    The following code is giving me the list of children from the Solutions node but NOT the bodyText.

    @{
        <h3>Our Solutions</h3>
        var solutionIntro = @Page.NodeTypeAlias == "Solutions";
        <p>@solutionIntro.bodyText</p>
        <p>Click to view more detail</p>    
        var myList = new List<umbraco.MacroEngines.DynamicNode>();           
        foreach (dynamic page in @Model.AncestorOrSelf(1).DescendantsOrSelf().OrderBy("CreateDate desc")) {
                            if(page.NodeTypeAlias == "Solution" )
                            {
                                    myList.Add(page);
                            }
                    }
            }
            <ul>
            @foreach(dynamic page in myList.Take(7)) {
                    <li><a href="@page.Url">@page.Name</a></li>
            }
            </ul>
    
  • Jeremy Pyne 106 posts 246 karma points MVP c-trib
    Dec 11, 2012 @ 22:58
    Jeremy Pyne
    0

     

    @{
       
    <h3>OurSolutions</h3>
           
    <p>Click to view more detail</p>        

     

             
    var myList = newListDynamicNode>();           
           
    foreach (dynamic page in @Model.AncestorOrSelf(1).DescendantsOrSelf("Solutions").OrderBy("CreateDate desc").Take(7)) {
                    <li><a href="@page.Url">@page.Name </a>
    @page.bodyText
    </li>
            }
            </
    ul>

     

  • Jeremy Pyne 106 posts 246 karma points MVP c-trib
    Dec 11, 2012 @ 23:02
    Jeremy Pyne
    1

    This bit here was outside the for statment.  @Page won't get you anything.  If your trying to get a property of a node your interating, IE print the bodyText for each link the sample above will do that.

    If there is a single page you want to get the text from, you need some way to identify/load it, IE:

    @Model.AncestorOrSelf(1).DescendantsOrSelf("Solutions").First().bodyText
    or
    @Model.NodeById(144).bodyText 

    Note thouth that the second method will have problems if you are using Courier to deploy the content.

  • Stephen Davidson 216 posts 392 karma points
    Dec 13, 2012 @ 12:15
    Stephen Davidson
    0

    Hey Jeremy...sorry I took so long to get back, thanks for your post, all working now. You were right i wanted content from a single page so i went for.

    @Model.AncestorOrSelf(1).DescendantsOrSelf("Solutions").First().bodyText

    Regards,

    S

Please Sign in or register to post replies

Write your reply to:

Draft