Is it possible to show all ancestors on a certain level without showing "self / current" page. I am using "AncestorOrSelf(2)" and that shows all ancestors like this:
first-item second-item third-item
But my problem is that I am currently on "first-item" page and I want to show related pages from here without showing the page im already on. It should look like this:
second-item third-item
And if I am on "second-page" then it should look like this:
first-item third-item
I hope that my description makes sense.
My current code looks like this:
@{ if (@CurrentPage.DocumentTypeAlias == "Portfolioitem") { var section = CurrentPage.AncestorOrSelf(2); { var childItems = section.Portfolioitem; foreach (var page in childItems) { Do something } } } }
With this code you should be able to get title and teaser, the thing is that you are strongly typed Razor so you need to use .GetPropertyValue("") to get the value from a field.
@if(CurrentPage.DocumentTypeAlias=="Portfolioitem"){ var siblings = Model.Content.Siblings(); foreach(var item in siblings.Where(x => x.Id != Model.Content.Id)) { <a title="@item.GetPropertyValue('title')" href="@item.Url">@item.GetPropertyValue("teaser")a> } }
Somtimes is necessary to specify the retun value, this can be done by
What do you mean about strongly typed Razor? Is there a better solution? I am still pretty new to programming and it would be nice to learn it the right way the first time.
It's because that there are two implementations of Razor in Umbraco, one is the dynamics CurrentPage, and the other is strongly typed Model.Content. The different is that the dynamics implemtation is more concise and with the strongly typed razor you will get intellisense if you are using e.g visual studio or webmatrix.
You could try to see Jeavon´s slides from the umbOktoberFest 2014 which you can download here.
And if you have a property on your document type so you can hide item from the navigation then I would implement this where too. The alias of the property needs to be umbracoNaviHide and the type is true/false
var preValue = Umbraco.GetPreValueAsString(Model.Content.GetPropertyValue<int>("category"));
foreach(var item in siblings.Where(preValue).Where(x => x.Id!=Model.Content.Id))
The code above is just a guess on how you maybe can do it. So it should take all siblings where the radio button is set to the same as the current page.
Hope this helps, if not I am out for ideas of how you could solve this at the moment.
AncestorOrSelf on certain level
Hi,
Is it possible to show all ancestors on a certain level without showing "self / current" page. I am using "AncestorOrSelf(2)" and that shows all ancestors like this:
first-item
second-item
third-item
But my problem is that I am currently on "first-item" page and I want to show related pages from here without showing the page im already on. It should look like this:
second-item
third-item
And if I am on "second-page" then it should look like this:
first-item
third-item
I hope that my description makes sense.
My current code looks like this:
// René
I am not that into the dynamic thing,
here's a solution for writing this in a typed manner:
Alternative
Thanks guys now I am on the right track but I still have a problem.
At the moment I can only get data such as "@item.name, @Item.Url" but how do I get my own data like "title, text, teaser"?
My code looks like this now:
If I try to insert CurrentPage instead of Model then it fails so I dont know what I am missing.
// René
Hi René
With this code you should be able to get title and teaser, the thing is that you are strongly typed Razor so you need to use .GetPropertyValue("") to get the value from a field.
Somtimes is necessary to specify the retun value, this can be done by
Hope this helps,
/Dennis
Hi Dennis
Thank you, that solved it. :-)
What do you mean about strongly typed Razor? Is there a better solution? I am still pretty new to programming and it would be nice to learn it the right way the first time.
// René
Hi René,
It's because that there are two implementations of Razor in Umbraco, one is the dynamics CurrentPage, and the other is strongly typed Model.Content. The different is that the dynamics implemtation is more concise and with the strongly typed razor you will get intellisense if you are using e.g visual studio or webmatrix.
You could try to see Jeavon´s slides from the umbOktoberFest 2014 which you can download here.
/Dennis
Hi Dennis,
Thanks again I really appreciate it.
// René
Hi again,
I have one more question regarding this.
This code just works perfect:
But how is it possible to implement a function that only show the same category as the current page?
At the moment the current page is in the category "graphics" and therefor I need it to only show items from that category.
// René
Hi René
Don´t know if is possible for you to do this like you do the check if so you don´t get currentpage in your navigation.
Perhaps you could, do something like this, but the code blow is untesed.
And if you have a property on your document type so you can hide item from the navigation then I would implement this where too. The alias of the property needs to be umbracoNaviHide and the type is true/false
Hope this helps,
/Dennis
Hi Dennis,
The category is set with a radio button does that change anything regarding your code above?
// René
Hi René
Here is the documentation on how you can get the value from radio button list https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/RadioButton-List
Perhaps you can do something like this:
var preValue = Umbraco.GetPreValueAsString(Model.Content.GetPropertyValue<int>("category"));
foreach(var item in siblings.Where(preValue).Where(x => x.Id!=Model.Content.Id))The code above is just a guess on how you maybe can do it. So it should take all siblings where the radio button is set to the same as the current page.
Hope this helps, if not I am out for ideas of how you could solve this at the moment.
/Dennis
Thanks Dennis I will give it a try and post the result in here.
Have a nice weekend.
// René
I have tried several solutions but none of them works. But I think that Dennis is on the right track.
Does anyone know a different approach?
At the moment it works so that it shows all items from all categories without showing the current item.
What I basically need is:
Do NOT show current item but show all other items in same category as current item which is set by a radio button.
I have attached this again because the post now is on two pages :-)
And my code looks like this:
Thanks in advance!
// René
I have still not managed to get it working, please look at the post above.
Does anyone know how to achieve this?
Thanks!
// René
is working on a reply...