Page 1 of 1

Stripping HTML tags from {$entry.body}

Posted: Sun Apr 06, 2008 2:58 pm
by yellowled
I have been notified of a small, well, not issue but downside of the Mimbo port. In many cases, it will not validate because of the bottom right column which displays articles as teasers.

Currently, those teasers are generated this way in entries_rcol.tpl:

Code: Select all

{$entry.body|truncate:400:" ..."}
I wasn't aware of the fact that this obviously truncates $entry.body at character no. 400 no matter what. I.e., the template takes the entry body's HTML code and truncates it at 400 chars, including the HTML tags, which in most of the cases will result in some HTML tags not being closed which will keep the page from validating almost all the time.

I figure there is no way to control truncating the article with all tags closed, especially not with regard to the variety of code people might use in $entry.body. So I was wondering: Is there a way to strip all HTML tags from $entry.body before or after truncating it? That way, I'd get a plain text output which could be put in <p></p> ...

YL

Re: Stripping HTML tags from {$entry.body}

Posted: Sun Apr 06, 2008 5:45 pm
by garvinhicking
Hi!

http://www.smarty.net/manual/en/languag ... p.tags.php might help you?

Regards,
Garvin

Posted: Sun Apr 06, 2008 6:27 pm
by Don Chambers
YL - I encountered the same issue.

Here's the problem with stripping all tags... lets say that within the first 400 characters, the entry body contained 3 paragraphs, already written with <p> tags.... ie:

Code: Select all

<p>This is my first paragraph.</p>
<p>This is my second paragraph.</p>
<p>This is my third paragraph.</p>
Now you strip out all tags and place that text within a single <p>......

Code: Select all

<p>This is my first paragraph.This is my second paragraph.This is my third paragraph.</p>
It is not going to have the same visual appearance as the original entry body.


At least the conclusion I came to is, for a brief "front page" summary of an entry, an unclosed <p> may not pass validation, but it isn't likely to cause a browser problem either.

The bigger problem is if the entry body contains a link, and the truncation causes it to open the <a>, but not close it.

Posted: Sun Apr 06, 2008 7:57 pm
by yellowled
Don Chambers wrote:It is not going to have the same visual appearance as the original entry body.
Of course it isn't.
Don Chambers wrote:At least the conclusion I came to is, for a brief "front page" summary of an entry, an unclosed <p> may not pass validation, but it isn't likely to cause a browser problem either.
Well, in a perfect world, users would simply limit the entry bodies of those articles assigned to "teasered" kategories tp less than 400 characters, put the rest of the article into the extended entry, and they'd be good to go.

Unfortunately, the world isn't perfect.

I'll check out strip_tags - thanks, Garvin. I really have to start reading the Smarty docs myself one of these days :)

YL