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?
Butas I understandyour structureinUmbracoyou, some nodes at the same lavel as Frontpage andprobablysome notesunder thefrontpage.
So if I understand your right you want to list a specific documenttype.
I amrelatively newtoRazor my self,butwillstill try tohelp.
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.
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. :-(
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".
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é
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
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é
Unfortunately i have not been able to solve this problem. Everytime i try to use (-1) i get an error.
/René
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 :)
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é
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 :)
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é
hmmmm do you have any more information other than script error? Are you using visual studio? Any clues in that?
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 -->
}
}
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é
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é
What version of Umbraco are you using? and you need to include umbraco.MacroEngines in your bin.
I am using version v6.0.2. umbraco.MacroEngines is already included in my bin.
hmmm then you should be able to use the DynamicNode have you got access to umbraco.macroextensions?
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é
Well done :) glad you fixed it. DynamicNode is brilliant! :) Charlie
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.