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

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Locked
Anastasis

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

Post 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.
Anastasis

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

Post 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.
sn3p
Forum Members
Forum Members
Posts: 169
Joined: Mon Oct 15, 2007 2:27 pm

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

Post by sn3p »

thanks, this was very helpfull :)
Locked

Return to “Layout and Design (CSS & HTML)”