Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Multiple Break Tags in Search Results

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 925 Views
  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Multiple Break Tags in Search Results Link to this post

    Hi all,

    In my current SilverStripe project, I'm using the search features to return content items from the site pages. These items have images, which the search strips out, which is good. However, where the images were, I'm left with multiple <br /> tags, so the results is shown with large gaps. Is there an easy way to remove extra break tags or perhaps compress them to a single break?

    Thanks,
    Lee

  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Re: Multiple Break Tags in Search Results Link to this post

    Anyone have any ideas?

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Multiple Break Tags in Search Results Link to this post

    Maybe something like this simple testcase will help (I'm no regexpert):

    $searchResult = 'aaaaaa<br />bbbbbbbb<br /><br />cccc';

    $pattern = '@(<br( /)*\>)+@i';

    $replacement = ''; //or use $replacement = '<br />';

    searchResult = preg_replace($pattern, $replacement, $searchResult);

  • Lazarus404
    Avatar
    Community Member
    71 Posts

    Re: Multiple Break Tags in Search Results Link to this post

    Thank you. I was hoping there would be a simple method I could override or a switch of some sort. There's obviously a method somewhere that strips out the images, so there must be a way to hijack that so that the output could be massaged.

    Lee

    925 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.