Show image in search results - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Show image in search results

  • Show image in search results
  • 24d7551e-37c1-6deb-a958-ff0000446526_capture.png

    I have custom content type built in with module builder, which have image and content.

    On the pages i drop widget displaying single item of that content. I want when using search widget results  to show finded content item with image and link to page where the content is.

    Any idea how to do that?

    Something like attached picture for example.

  • Anyone?
  • Thanks, this will work for the image, but it won't work for getting url where the content is published even if I use GetItemLocations method. When I use mvc widget that is automatically generated by module builder and create my own or edit built in template GetItemLocations() return the pages where contentItem  is published, but if I create my mvc widget and display the same content type GetItemLocations() does not return the pages.

    This is my custom mvc widget probably I need to add something so when i call GetItemLocations() in search widget built in template as you say to return pages where is published?

    public ActionResult Index()
            var selectedContent = Model.CreateListViewModel(null, 1).Items.FirstOrDefault();
            ContentViewModel viewModel = null;
            if (selectedContent != null)
                viewModel = new ContentViewModel(selectedContent.Fields.Content);
                viewModel.Title = selectedContent.Fields.Title;
                viewModel.MainImage = new ImageHelper().InitializeImageViewModel(selectedContent.Fields.MainImage);
            return View(GetListTemplateName("List.Content"), viewModel);
  • If you are using MVC search widget, you can add inside template something similar like this one:

    if (((Telerik.Sitefinity.Services.Search.Model.Document)item).ItemType.ToString() == "type of you dynamic item")
                    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                    Type type = TypeResolutionService.ResolveType("type of you dynamic item");
                    var itemId = new Guid((string)item.GetValue("Id"));
                    var itemObject = dynamicModuleManager.GetDataItem(type,itemId);
                    if (itemObject != null)
                            <img src="@item.GetValue("Image")" alt="@item.GetValue("Title")" width="120"/>@item.GetValue("Title")
  • f1db551e-37c1-6deb-a958-ff0000446526_pagew-where-items-published.png

    For sure, you need to implement IContentLocatableView for your custom widget. You can check this article, which can help you:

    Then, when u implemented it, you need to go to the page, where you placed this widget and republish this page. Because only in this case, Sitefinity will update content locations.

    Then go to your dynamic module view on Backend and click "Pages where items like this are published" (attached image) and check if you page isexists. Also you can order the primary location of you dynamic item.

    Then, reindex your search. 


    Hope, this will help for you

  • Thanks, it works.