I am using some data from a folder called data which is on the same level as home. How is it possible to always keep the same rootNode. I use the code below but it does not work. When I fetch data from the data folder, then it changes the navigation so that it shows all the items in the data folder.
var home = @CurrentPage.Site();
My structure looks like this:
Is there a way to always use the exact same rootNode regardless if the content is from the data folder or home folder?
What does your full code look like where you experience this issue?
If you don't attach a template to the date elements then they should not be populated with a URL either if I remember correctly.
But it would be nice to see the full code that is causing the issue - I have used a similar approach as the one you illustrate on the image above and not had any trouble with changes in navigation even though I loaded content from the "Data/Elements" section...so need to see the issue in action :)
That actually makes sense, because .Site() goes all the way up to level 1, so when you're in the "Forside" section it'll return Forside, and in the Data section, the Data node will be hit. What you really want is to go all the way to the root node and then pick the Forside node below that - something like this:
var home = @CurrentPage.Root().Down("ForsideAlias");
This should work if I understand this page correct.
"ForsideAlias" should of course be replaced with the actual nodeTypeAlias of your "Forside" node
On this project it is very important that almost all data / content is stored in the data folder, because it should be very easy to change the frontpage to another layout / template without deleting all the children below the frontpage.
But wondering what did not work when you tried using Chriztians example? Did you get a yellow screen of dead? If so what did the error message say? And what did the error message in the /app_data/logs file say?
It should be fairly easy to achieve what you want using CurrentPage.AncestorOrSelf(1).Children.Where("Visiable") otherwise though - But since .Site() should do that for you according to what Chriztian writes above it might be more conventional to use that approach :)
Always use same rootNode
Hi,
I am using some data from a folder called data which is on the same level as home. How is it possible to always keep the same rootNode. I use the code below but it does not work. When I fetch data from the data folder, then it changes the navigation so that it shows all the items in the data folder.
My structure looks like this:
Is there a way to always use the exact same rootNode regardless if the content is from the data folder or home folder?
// René
Hi René
What does your full code look like where you experience this issue?
If you don't attach a template to the date elements then they should not be populated with a URL either if I remember correctly.
But it would be nice to see the full code that is causing the issue - I have used a similar approach as the one you illustrate on the image above and not had any trouble with changes in navigation even though I loaded content from the "Data/Elements" section...so need to see the issue in action :)
/Jan
Hi René,
That actually makes sense, because
.Site()
goes all the way up to level 1, so when you're in the "Forside" section it'll return Forside, and in the Data section, the Data node will be hit. What you really want is to go all the way to the root node and then pick the Forside node below that - something like this:This should work if I understand this page correct.
"ForsideAlias" should of course be replaced with the actual nodeTypeAlias of your "Forside" node
/Chriztian
Hi Jan and Chriztian
Chriztian:
I did not manage to get it working with your example.
Jan:
See my code below:
On this project it is very important that almost all data / content is stored in the data folder, because it should be very easy to change the frontpage to another layout / template without deleting all the children below the frontpage.
// René
Hi René
Ok, I understand your issue now.
But wondering what did not work when you tried using Chriztians example? Did you get a yellow screen of dead? If so what did the error message say? And what did the error message in the /app_data/logs file say?
It should be fairly easy to achieve what you want using CurrentPage.AncestorOrSelf(1).Children.Where("Visiable") otherwise though - But since .Site() should do that for you according to what Chriztian writes above it might be more conventional to use that approach :)
Looking forward to hearing from you.
/Jan
Hi Jan
No the navigation just disappears on every page.
// René
I am following Chriztian's example. Try to see this code, am I doing something wrong?
// René
Hi René,
The
home
variable points to the Forside node, so you need to iterate its children and not itself, e.g.:/Chriztian
Hi Chriztian
That's perfect now it is working.
Thanks!
// René
is working on a reply...