1

We have an Item bucket of News articles created for one of our client websites. We want to display those items on the News page and Press Release page since the content is somewhat the same. We are using Solr search. Is it possible to use these items on both pages? It will be very helpful if some explanation is provided on this. Thanks.

Edit #1: I tried implementing Sumits's answer. Got the results I needed. Now my concern is, How do I manage the URL of each record? Since each record in the bucket is a detail page itself.

So for example News/2022/10/01/35/45/Article-One is the path of Bucket Item. site.com/press-release is the Press Release listing page.

Now on this page, I want to list News/2022/10/01/35/45/Article-One with the URL: site.com/press-release/News/2022/10/01/35/45/Article-One.

How can I manage that?

Similarly for any other listing page.

3 Answers 3

0

If controls added on both News and Press Release pages have same and content is also similar then you can use same bucket for both news and press release pages.

You can create a Controller rendering. And on this rendering you can write your logic to get News Article bucket items by targeting News Items template.

For more information you can refer this article for getting started with solr in Sitecore

https://labs.tadigital.com/index.php/2019/06/19/the-complete-guide-to-getting-started-with-solr-in-sitecore/.

Hope this helps you.

0

If you are using Solr search and getting the items using content API, then I think you can add the News Articles items on both pages.

You need to create a controller rendering and under that controller, need to write the logic to get items or type News Articles using content API and pass the list of items to your rendering.

Your rendering will create a loop to render those items.

Now you can use this rendering on any of the News page and Press Release page to show the data.

To get items you can use this code and update it accordingly as per your requirements.

    public List<T> GetAllItemsFromBucket(string bucketPath)
    {
        var index = ContentSearchManager.GetIndex("content_index");
        using (var context = index.CreateSearchContext())
        {
            var results = context.GetQueryable<T>().Where(x => x.Path.StartsWith(bucketPath)).ToList();
            foreach (var result in results) _service.Map(result);
            return results;
        }
    }

For more details to iterate over buckets, use this link.

https://www.anycodings.com/1questions/1069698/iterating-over-sitecore-bucket-items

I hope this makes sense.

1
  • I tried your suggestion, and I am getting results. I need help while rendering those results. Can you please check the question description? I have updated my query there. Thank you. Feb 27 at 14:15
0

If bucket item contain the same data then you can use the same item data on multiple pages. There are many way to get the data from the bucket through programming. However, the best way to get all the data from the bucket is Sitecore Content Search API.

You can read about content search API on the link below :-

https://doc.sitecore.com/xp/en/developers/90/platform-administration-and-architecture/search-and-indexing-overview.html

https://ankitjoshi2409.wordpress.com/tag/content-search-api/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.