Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 944 posts 2076 karma points
    Jul 21, 2015 @ 22:38
    Nigel Wilson
    1

    Javascript / Contour Forms in Searech Results

    Hi there

    Just a bit of feedback for consideration.

    We have come across a case whereby a Contour form is embedded in the page content, and when that page is returned in search results the associated JavaScript of the form is detailed in the preview data.

    Obviously the Umbraco.StripHtml() method is built in, but below is my amended method for rendering results for content.

    @helper RenderContentResult(SearchViewModel model, IPublishedContent result)
    {
        string heading = !string.IsNullOrWhiteSpace(result.GetPropertyValue<string>("pageHeading")) ? result.GetPropertyValue<string>("pageHeading") : result.Name;
    
        <div class="ezsearch-result">
            <h2><a href="@result.Url">@heading</a></h2>
            @foreach (var field in model.PreviewFields.Where(field => result.HasValue(field)))
            {
                string summaryContent = result.GetPropertyValue(field).ToString();
    
                Regex rRemScript = new Regex(@"<script[^>]*>[\s\S]*?</script>");
                summaryContent = rRemScript.Replace(summaryContent, "");          
    
                string strippedSummaryContent = Umbraco.StripHtml(summaryContent).ToString();
    
                <p>@Highlight(Truncate(strippedSummaryContent, model.PreviewLength), model.SearchTerms)</p>
                break;
            }
        </div>
    }
    

    Cheers

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft