Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I'm trying to find a way to trim out whitespace from the beginning and end of a richtext content block.

I have a few lines like this:

Code: Select all
<p>
   <cms:excerpt count='190' truncate_chars='1'>
      <cms:show blog_content />
   </cms:excerpt>
</p>


This returns all text content that the current blog post contains and makes a 190 characters long except out of it. My problem is that when the blog post contains other than text elements there's a random amount of whitespace at the beginning of the excerpt.

I want to trim it away because it looks somewhat bad in my layout if the blog post excerpts start with a whitespace.

I automatically thought could I use the PHP trim() function to achieve this but I couldn't get it to work. I'm not even sure if it's possible to get Couch to spit out the excerpt and then run it through the trim() function.

As always, every bit of help and advice is greatly appreciated!
Hi,

The problem you mention will occur when there are empty elements at the beginning of the content e.g.
<p>&nbsp;</p>
The 'strip_tags' PHP function used by the cms:excerpt tag strips off the HTML tags but leaves behind the '&nbsp;'s.

While we can certainly use PHP in tandem with Couch (via cms:php tag) to correct this, I think this is an issue important enough to warrant a fix in the core (more so because these '&nbsp;'s also fudge the character count).

I am attaching a modified version of a core file - 'tags.php' (IMP: needs Couch v1.3). Please replace the original file within your 'couch' installation folder with the one attached.

Do let me know if this fixes the problem and I'll commit the changes.

Thanks.

Attachments

At least in my case this fixes the problem. Superb.
3 posts Page 1 of 1
cron