Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    Mar 12, 2013 @ 15:04
    René Andersen
    0

    How to go up the tree to the Root (Content)

    Hi

    I am about to make a website where i need to go up the tree to the Root (Content) and then i need to search for a specific documenttype wich is located in the Root / Content at the same level as my frontpage. I need a portfolio to be located in the Root so that multiple pages can use data from it. Does my question make sense?

    Thanks in advance!

    Kind regards
    René

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 12, 2013 @ 15:58
    Dennis Aaen
    0

    Hi Rene,

    Do not know if I understand your question correctly.

    But as I understand your structure in Umbraco you, some nodes at the same lavel as Frontpage and probably some notes under the frontpage.

    So if I understand your right you want to list a specific documenttype.

    I am relatively new to Razor my self, but will still try to help.

    The -1 should get you to the root node, and from there with the code below, you will get the name of the nodes, if they have the documenttype Textpage. I hope remember correctly.

    @{var rootNode =Model.AncestorsOrSelf(-1);}

    <ul>
       
    @foreach(var item in rootNode.Textpages.Where("Visible"))
       
    {
       
    <li><a href="@item.Url">@item.Name</a>li>
    }
    ul>

    Hope this can help you or a least inspire you to find the right solution.

    /Dennis

  • René Andersen 238 posts 684 karma points
    Mar 16, 2013 @ 22:31
    René Andersen
    0

    Hi Dennis,

    Thanks for your answer I will give it a try and get back to you if it works out for me.

    Kind regards

    René

  • René Andersen 238 posts 684 karma points
    Mar 30, 2013 @ 22:56
    René Andersen
    0

    Unfortunately i have not been able to solve this problem. Everytime i try to use (-1) i get an error.

    /René

  • Charles Afford 1163 posts 1709 karma points
    Mar 31, 2013 @ 16:49
    Charles Afford
    0

    Hi you can just do

    DynamicNode node = new DynamicNode(-1).  <<< siteroot.

    node.descandents.where(x=>x.somemethod == "somevalue")

    {

    //logic

    }

    Have not tested this but it will something like that.  Charlie :)

  • René Andersen 238 posts 684 karma points
    Apr 02, 2013 @ 21:48
    René Andersen
    0

    Hi Charles,

    Im a pretty new to Razor so maybe you can help me a little more. Can you give me a hint where to put in your "DynamicNode" examples in the code below:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
    var nodes = Model.AncestorOrSelf().Descendants("BusinessDetails");
    @Model.name
    <div class="extra-info face">
    @foreach (var page in nodes)
    {
    <div class="span3">
    <div class="service-overview">
    <h6>@page.nameOwner</h6>
    <img src="@page.image" alt="" />
    <div class="service-overview-overlay">+</div>
    </div><!-- end .service-overview -->
    </div><!-- end .span3 -->
    }
    </div>
    }

    Thank you!

    //René

  • Charles Afford 1163 posts 1709 karma points
    Apr 03, 2013 @ 10:04
    Charles Afford
    0

    Hi, well at the moment you are searching from the page you are on downwards.  Model. is always going to be the page you are on.

    So, to go from the site root down.  You can do:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @Model.name // currentpage name

    @{

    DynamicNode node = new DynamicNode(-1).  <<< siteroot.

     

    // foreach node under siteroot with doctype BussinessDetails

    foreach(DynamicNode childNode in node.Descendants.where(x=>x.doctypealias ==  BusinessDetails)

    {

    <div class="span3">

     <div class="service-overview">
     
    <h6>@childNode.nameOwner</h6>
     
    <img src="@Umbraco.TypedMedia(childNode.GetProperty("YOURIMAGEPROPERTYALIAS").Value.ToString()).GetPropertyValue("umbracoFile")"/> 
     
    <div class="service-overview-overlay">+</div>
     
    </div>
    <!-- end .service-overview -->

    </div><!--end.span3 -->

    }

    }

    This amy need some work, but it should work for the most part :)

  • René Andersen 238 posts 684 karma points
    Apr 03, 2013 @ 14:27
    René Andersen
    0

    Hi Charles

    I have tried to use your code but I only get the message "Script error". Can you see if there is something missing in your code? I mean a "@" or ";" At the moment I am shooting in the dark. :-(

    By the way I really appreciate your help so far.

    //René

  • Charles Afford 1163 posts 1709 karma points
    Apr 03, 2013 @ 22:07
    Charles Afford
    0

    hmmmm do you have any more information other than script error?  Are you using visual studio?  Any clues in that?

  • Charles Afford 1163 posts 1709 karma points
    Apr 03, 2013 @ 22:24
    Charles Afford
    0

    You will need to find the namespace for TypedMedia but that code should work :).  What version of Umbraco are you using? 

     

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @Model.name // currentpage name

    @{

    DynamicNode node = new DynamicNode(-1);

    // foreach node under siteroot with doctype BussinessDetails

    foreach(DynamicNode childNode in node.Descendants().Where(x=>x.NodeTypeAlias ==  "BusinessDetails")) 

    {

    <div class="span3">

     <div class="service-overview">

     <h6>@childNode.nameOwner</h6>

     <img src="@Umbraco.TypedMedia(childNode.GetProperty("YOURIMAGEPROPERTYALIAS").Value.ToString()).GetPropertyValue("umbracoFile")"/> 

     <div class="service-overview-overlay">+</div>

     </div><!-- end .service-overview -->

    </div><!--end.span3 -->

    }

    }

  • René Andersen 238 posts 684 karma points
    Apr 04, 2013 @ 10:21
    René Andersen
    0

    Hi Charles,

    I am using version v6.0.2. Unfortunately i am not using Visual Studio. Is there a way to make the browser tell me more about the error? Instead of only "Error loading MacroEngine script".

    //René

  • René Andersen 238 posts 684 karma points
    Apr 11, 2013 @ 10:43
    René Andersen
    0

    Hi Charles,

    I have tried to run this in Visual Studio and I get this error:

    The type or namespace name 'DynamicNode' could not be found (are you missing a using directive or an assembly reference?)

    Do you have any idea what's wrong?

    //René

  • Charles Afford 1163 posts 1709 karma points
    Apr 11, 2013 @ 16:23
    Charles Afford
    0

    What version of Umbraco are you using? and you need to include umbraco.MacroEngines in your bin.

  • René Andersen 238 posts 684 karma points
    Apr 11, 2013 @ 16:49
    René Andersen
    0

    I am using version v6.0.2. umbraco.MacroEngines is already included in my bin.

  • Charles Afford 1163 posts 1709 karma points
    Apr 11, 2013 @ 21:34
    Charles Afford
    0

    hmmm then you should be able to use the DynamicNode have you got access to umbraco.macroextensions?

  • René Andersen 238 posts 684 karma points
    Apr 12, 2013 @ 10:36
    René Andersen
    100

    Hi Charles

    I managed to get it working with some minor changes:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines;

    @{
    DynamicNode rootNode = new DynamicNode(-1);
    foreach (DynamicNode childNode in rootNode.Descendants().Where(x => x.NodeTypeAlias == "BusinessDetails"))
    {
    <div class="span3">
    <div class="service-overview">
    <h6>@childNode.GetProperty("nameOwner").Value</h6>
    <img src="@Umbraco.TypedMedia(childNode.GetProperty("imageOwner").Value.ToString()).GetPropertyValue("umbracoFile")"/>
    <div class="service-overview-overlay">+</div>
    </div><!-- end .service-overview -->
    </div><!--end.span3 -->
    }
    }

    Thank you for your time and help. :-)

    //René

  • Charles Afford 1163 posts 1709 karma points
    Apr 15, 2013 @ 21:22
    Charles Afford
    0

    Well done :) glad you fixed it.  DynamicNode is brilliant! :)  Charlie

Please Sign in or register to post replies

Write your reply to:

Draft