I have a question regarding bucket items in Sitecore.
I have following structure:
I want to create a button on the 'test' detail page that goes back to the top bucket 'News overview'. Normally I would do something like:
LinkManager.GetItemUrl(Sitecore.Context.Item.Parent)
The problem here is that the direct parent is the bucket '44' and not 'News overview'. What would be the best way to create a link to the overview bucket?
There is an extension method in the Item that gives you the bucket item of your current item.
Its in the Sitecore.Buckets.Extensions
namespace in the Sitecore.Buckets.dll
assembly.
You can use it like this:
var bucketItem = Sitecore.Context.Item.GetParentBucketItemOrParent();
var urlToBucket = LinkManager.GetItemUrl(bucketItem);
You can also use the BucketManager to check if an item is contained within a bucket:
BucketManager.IsItemContainedWithinBucket(Sitecore.Context.Item)
You could recursively call [Sitecore.Data.Items.Item].Parent
and perform a check each time until you get to an item with a template id that either is the template ID that you are looking for or is different from the bucket folders' template IDs.
Alternatively, you could also use [Sitecore.Data.Items.Item].Axes.GetAncestors()
, but this will return you all of the ancestors of the Item
in top-down order.
Parent/child relationships and methods and techniques for accessing one another did not actually change in Sitecore 7. As such, any techniques that you used in Sitecore 6 should still be usable in Sitecore 7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With