Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Remove images from search results


Go to End


15 Posts   4265 Views

Avatar
Stompit

Community Member, 17 Posts

10 August 2010 at 2:09pm

Thanks Willr! :) I no longer get an error message, however the search results still contain images, the code shows the same markup as the original search method.

Any ideas?

Thanks
D

Avatar
Stompit

Community Member, 17 Posts

16 August 2010 at 6:06pm

Bumpiddy bump bump :)

Avatar
Stompit

Community Member, 17 Posts

17 August 2010 at 12:35pm

Hi Willr,
I've gone through this all with a fine tooth comb, have also double checked to ensure that the live site is working with the updated code. Unfortunately, the search results still include images :( It would be great if we could nail this one as I have noticed a couple of other similar questions on the forum.

The problem images are included in the body content thusly:


<p><img blah blah>blah blah</p>

Avatar
Willr

Forum Moderator, 5523 Posts

17 August 2010 at 6:34pm

Oh sorry Stompit I didn't know you were referring to images inside the content. My code will only remove images from being searched as standalone assets. Removing images from posts is another kettle of fish.

A couple ways you could do it:

- The easiest way (and what I normally do) is display the results using $Content.NoHTML which will strip all the formatting / images / heading out.

- If you like formatting then a possible solution is to have a regular expression which replaces the image tags with nothing. I'm not a regular expression expert so would have no clue what the actual code to get that working but how you would do it would be to have a function in your Page class like

function NoImages() {
$content = $this->Content;

return DBField::create('HTMLText', preg_replace("/<img[^>]+\>/i", " ", $content));
}

Avatar
Stompit

Community Member, 17 Posts

18 August 2010 at 8:28pm

Thanks again Willr :)

The saga continues...

Referring back to my original code there is no reference to $content, however I have tried to assign the .NoHTML to $form an a few other elements with no luck, keeps throwing errors. I am working with the page.php file.

Would I find the $Content in another file, or am I missing something obvious!? :)

Thanks
D

Avatar
Willr

Forum Moderator, 5523 Posts

18 August 2010 at 8:47pm

Would I find the $Content in another file, or am I missing something obvious!?

This would be in your search results template. Page_results.ss or similar.

Avatar
Stompit

Community Member, 17 Posts

20 August 2010 at 6:18pm

Hooraa! Modifying that template worked like a charm!!

I didn't end up using the .NoHTML, doing so produced a huge chunk of text in the results.

I had: $Content.FirstParagraph(html) which I changed to $Content.FirstParagraph, seemed to do the job :)

Thanks a million for all your help!

Best Regards
D

Go to Top