More in this section

Forums / Developing with Sitefinity / Show image in search results

Show image in search results

6 posts, 1 answered
  1. Iliyan
    Iliyan avatar
    0 posts
    Registered:
    17 Aug 2016
    26 Jan
    Link to this post

    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.

  2. Iliyan
    Iliyan avatar
    0 posts
    Registered:
    17 Aug 2016
    31 Jan
    Link to this post
    Anyone?
  3. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    31 Jan in reply to Iliyan
    Link to this post

    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)
                    {
     
                        <div>
                            <img src="@item.GetValue("Image")" alt="@item.GetValue("Title")" width="120"/>@item.GetValue("Title")
                             
                        </div>
                    }
                }
  4. Iliyan
    Iliyan avatar
    0 posts
    Registered:
    17 Aug 2016
    31 Jan
    Link to this post

    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);
        }
  5. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    01 Feb in reply to Iliyan
    Link to this post

    For sure, you need to implement IContentLocatableView for your custom widget. You can check this article, which can help you: http://knowledgebase.progress.com/articles/Article/How-to-implement-IContentLocatableView-for-custom-widgets

    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

    Answered
  6. Iliyan
    Iliyan avatar
    0 posts
    Registered:
    17 Aug 2016
    01 Feb
    Link to this post
    Thanks, it works.
6 posts, 1 answered