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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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
Bumpiddy bump bump :)
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>
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));
}
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
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.
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