You want:
echo("<p>" . $text->truncate($thisstory['Story']['plot']) . "</p>");


FWIW, I wrote a function just last night that acts the same as
Text::truncate() but for HTML content. There are a couple of problems
with using the Text method on HTML content:

1) It will count the characters of your tags as part of the text
length to limit to. My function takes these into consideration, so the
limit you pass will be honoured.

2) It will inevitably leave you with an unbalanced HTML snippet. So,
an unclosed <strong> will ruin the rest of your page. My function
relies on the Tidy extension to clean up. If Tidy isn't available, it
passes the string to Text::truncate().

I found and fixed a couple of bugs this morning but there's still one
(that I know of) left. I'll post it later when I get a chance to have
another look at it. Although, I was planning to turn the function into
a Helper first. Maybe I'll do that.

I'll also post easy instructions for installing libtidy and the Tidy ext.

On Thu, Mar 6, 2008 at 1:08 PM, Toon Gorissen <[EMAIL PROTECTED]> wrote:
>
>  I managed to include the TextHelper in the controller, but I don't
>  understand where to actually use the excerpt function. I'm new to
>  CakePHP.
>
>  My controller:
>  var $helpers = array('Html','Javascript', 'Ajax', 'RfRating', 'Text');
>
>  My view:
>  echo("<p>" . truncate($thisstory['Story']['plot']) . "</p>");
>
>  But that doesn't seem to work:
>  Fatal error: Call to undefined function truncate() in /Applications/
>  MAMP/htdocs/metatube/app/views/stories/index.thtml on line 7
>
>
>
>  On 6 mrt, 18:36, "dr. Hannibal Lecter" <[EMAIL PROTECTED]> wrote:
>  > Well, if your stories are plain text data, you need to use TextHelper
>  > (http://api.cakephp.org/1.2/class_text_helper.html) in your view. The
>  > ticket you posted is a patch for making excerpts of html data.
>  >
>  > Toon Gorissen wrote:
>  > > I'm using the following code in my stories_controller:
>  >
>  > > function index(){
>  > >    $stories = $this->Story->findAll(null, array('id', 'plot', 'author',
>  > > 'created'), 'created DESC');
>  > >    $stories_array = array();
>  > >    foreach($stories as $story){
>  > >            $story_id = $story['Story']['id'];
>  > >            $stories_array[$story_id] = $this->RfRating-
>  > > >getRatingInfo($story_id, $_SERVER['REMOTE_ADDR']);
>  > >    }
>  > >    //$this->set('stories', $this->Story->findAll(null, array('id',
>  > > 'plot', 'author', 'created'), 'created DESC'));
>  > >    $this->set('stories', $stories);
>  > >    $this->set('ratingInfo', $stories_array);
>  > > }
>  >
>  > > Now I would like to truncate (or make an excerpt of) the plot
>  > > variable. I've read a ticket on makings exerpts (https://
>  > > trac.cakephp.org/ticket/2306), but I don't quite understand how to
>  > > implement it.
>  >
>  > > Could someone help me? Thanks!
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to