Page 1 of 1

Stripping characters/text from news {$entry->content}

Posted: Thu Aug 02, 2007 11:30 am
by Anastasis
Hello everyone

I have been offline for quite a few weeks, first busy with other things and then in hospital (but am OK now), so have rather dropped the ball on developing my employer's new website using CMS for the first time.

I have today been picking up where I left off from with sorting out our news display. We have a separate news index page (for which I have created a custom summarytemplate) that displays the news item title, its post date and a summary of the first 600 characters (which I may increase) from the content. This is the summarytemplate:

Code: Select all

<!-- Start News Display Template -->

{foreach from=$items item=entry}
  <h2>{$entry->titlelink}</h2>
  <span class="news_index_content_date">{$entry->formatpostdate}</span>
 {$entry->content|truncate:600}
{/foreach}

<!-- End News Display Template -->
However, I am experiencing a problem using this technique as the

Code: Select all

{$entry->content|truncate:600}
includes everything such as an image (which we occasionally use to lead the news story) and also paragraph tags.

Whilst I know I could manually copy and paste the text I want to use into the Summary field in the editor for the news story,  ideally, I don't want to have to do that every time as (a) it takes longer and (b) this task will be carried out by an end user for whom it would be more difficult.

So, is there a way of stripping out an image and any HTML tags (such as ) from the

Code: Select all

{$entry->content|truncate:600}
so I can make this automated?

As ever, thanks in advance for anyone who can help with this.

Re: Stripping characters/text from news {$entry->content}

Posted: Thu Aug 02, 2007 3:24 pm
by Anastasis
Just reporting that I have found an answer using Smarty (note to self: learn to look there first).

I have used the Smarty function: strip_tags resulting to this revision to the template:

Code: Select all

<!-- Start News Display Template -->

{foreach from=$items item=entry}
  <h2>{$entry->titlelink}</h2>
  <span class="news_index_content_date">{$entry->formatpostdate}</span>
  <p>{$entry->content|strip_tags:false|truncate:300}</p>
{/foreach}

<!-- End News Display Template -->
The addition of the tags wrapping the line containing strip_tags is because strip_tags also took out the valid tags which were referenced in my CSS to set the right text style. The :false parameter means that for every tag that is stripped Smarty replaces them with a '' rather than a space (the default).

Hope this helps someone.

Re: Stripping characters/text from news {$entry->content}

Posted: Tue Dec 11, 2007 2:09 am
by sn3p
thanks, this was very helpfull :)