Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Nov 27, 2018 @ 10:39
    Dibs
    0

    Umbraco Examine custom search return url to content

    Dear Umbraco Examine experts

    I have built, on top of OOTB Umbraco search, a custom Index to search descendants from a certain node, i.e searchable path. I am able to display key/value as desired i.e

    <ul>
        @foreach (var result in searchResults)
        {
            <li>
                @{
                    foreach (var field in result.Fields)
                    {
                        <div class="row">
                            @if (field .Key == "nodeName")
                            {
                               <div class="col">
                                   @f.Value;
                                </div>
                            }
                            @if (field .Key == "urlName")
                            {
                                <div class="col">
                                    <a href="@field .Value">@field .Value;
                                </div>
                            }
                        </div>
                    }             
                }
            </li>
        }
    </ul>
    

    How can i render the correct link to an item from the search results ?

    <a href="@field.Value">@field.Value
    

    the above renders the urlName and appends it to the search results page. i.e http://my.domain.com/search/field-value-url.

    I would like it to render like @field.Url, which gives you the correct url to the item.

    Thanks Dibs

  • Garðar Þorsteinsson 118 posts 564 karma points
    Nov 27, 2018 @ 10:47
    Garðar Þorsteinsson
    100

    Hi,

    Think it would be best if you get the IPublishedContent for each result to get the Url.

    @{
        foreach (var result in searchResults) {
            var node = Umbraco.TypedContent(result.Id);
            <div><a href="@node.Url">@node.Name</a></div>
        }
    }
    
  • Dibs 202 posts 991 karma points
    Nov 27, 2018 @ 10:53
    Dibs
    0

    Cheers Garðar

    reading your reply, i remembered i have done that before : / getting ID and then that exposes .Url

    Dibs : )

Please Sign in or register to post replies

Write your reply to:

Draft