Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 21, 2016 @ 19:54
    Michaël Vanbrabandt
    0

    ezSearch add more details into the results container

    Hi,

    I am using the ezSearch package in my latest project. Everything is working fine but I want to add more details in the result.

    I have edit the ezSearch template manually because some required fields are standard umbraco property fields. And using the previewFields you can't access them ( like for example displaying the url ).

    But what I would like to add is something like Google. A breadcrumb list to the result page with links to all the parents.

    How can I do this?

    Do I need to create a new macro and call this in the ezSearch macro in some sort of way or...

    Can anyone guide me in this?

    /Michael

  • Sotiris Filippidis 286 posts 1501 karma points
    Jun 21, 2016 @ 22:21
    Sotiris Filippidis
    0

    Well, I don't know if this will work out of the box, and it will probably need some tweaking, but the general idea is as follows:

    The RenderContentResult helper (ezSearch.cshtml, line 250 currently on GitHub) knows the IPublishedContent that you are displaying at that time.

    What you could probably do is create a partial view (under /Views/Partials, let's call it PageBreadcrumb.cshtml) which will render a breadcrumb and call it from there. Here's a simple partial view for that:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        IPublishedContent currPage =  Model;
        string[] breadcrumbIds = currPage.Path.Split(',');
            foreach (string breadcrumbId in breadcrumbIds)
            {
                int id = int.Parse(breadcrumbId);
                if (id > 0)
                {
                    IPublishedContent item = Umbraco.TypedContent(id);
                    if (item.IsVisible() && !breadcrumbId.Equals(breadcrumbIds.Last()))
                    {
                        <a href="@Umbraco.NiceUrl(id)">@item.Name</a> @Html.Raw("/ ");
                }
                if (breadcrumbId.Equals(breadcrumbIds.Last()))
                {
                    <span>@item.Name</span>
                }
            }
        }
    }
    

    And call it like this:

    ...
        <div class="ezsearch-result">
                <h2><a href="@result.Url">@result.Name</a></h2>
            @Html.Partial("Pagebreadcrumb", result)
    ...
    

    Where "result" is the IPublishedContent passed as parameter to the helper function.

    This could also be a macro, not a partial view, but it was easier to show you with a partial view since I already had the code handy. Please give it a try and let me know if you managed it or got stuck somewhere.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 22, 2016 @ 11:03
    Michaël Vanbrabandt
    0

    Ok got it working using the suggesting of creating a new macro and call this in the ezSearch macro.

    1) Created a new Macro with one param Content Picker which contains the id of the current node

    2) Called the macro from ezSearch and give the result id as param to the macro

    @Umbraco.RenderMacro("ezBreadcrumb", new { currentNodeId = result.Id })
    

    /Michael

  • Sotiris Filippidis 286 posts 1501 karma points
    Jun 22, 2016 @ 13:28
    Sotiris Filippidis
    0

    That's great. Essentially it's the same thing, happy to know it worked for you!

Please Sign in or register to post replies

Write your reply to:

Draft