Truncate Summaries

Permalink 2 users found helpful
Concrete5 ver. 5.5.1.
Block Page List.
Type of Pages Blog Entry.
In custom template "Blog Index "the Truncate Summaries does not working properly.
Iam setting for example Truncate descriptions after 250 characters and the truncate does not work.
I have set a description of an article of course...
Any suggestion?

Thanks

spyrou
View Replies: View Best Answer
spyrou replied on at Permalink Reply
spyrou
Any help please!!!
12345j replied on at Permalink Reply
12345j
how does it now work? does it not cut the article? cut it to 100? more details would help.
spyrou replied on at Permalink Reply
spyrou
Exactly not cut the article...
spyrou replied on at Permalink Reply
spyrou
Can anyone advice me please ?
wagdi replied on at Permalink Reply
wagdi
Might be a silly question but have you tried clearing the cache?
spyrou replied on at Permalink Reply
spyrou
Yes I have cleared the cache files. The issue is that the "Blog Index" custom template does not truncate the article description characters...
spyrou replied on at Permalink Reply
spyrou
Is this a bug of C5-5.5.1 ? Iam trying to understand. Nobody have the same problem with this template?
mkly replied on at Permalink Best Answer Reply
mkly
Ya, you might be right on this.
in /concrete/blocks/page_list/templates/blog_index.php
<div class="excerpt">
  <?php 
    $a = new Area('Main');
    $a->disableControls();
    $a->display($cobj);
  ?>
</div>


Maybe modify it to try this.
<div class="excerpt">
  <?php
    $a = new Area('Main');
    $a->disableControls();
    if($truncateChars) {
      $th = Loader::helper('text');
      ob_start();
        $a->display($cobj);
      $excerpt = ob_get_clean();
      echo $th->entities($th->shorten($excerpt,$truncateChars));
    } else {
      $a->display($cobj);
    }
  ?>
</div>


It looks like the blog_index is set to show the 'Main' Area of the blog page not the page description so I grabbed that in a buffer and cleaned and shortened it. Let me know if it works.

EDIT: updated as per @jjcdesign's comment below.
spyrou replied on at Permalink Reply
spyrou
There is a fatal error:
Fatal error: Call to a member function entities() on a non-object in /home/easynetg/public_html/c5/concrete/blocks/page_list/templates/blog_index.php on line 42

this line of code is:
$textHelper->entities($textHelper->shorten($excerpt,$truncateChars));
mkly replied on at Permalink Reply
mkly
oops, that should be this.
$th->entities($th->shorten($excerpt,$truncateChars));

FYI: I'm not sure if you know this as you are new around here. But the people helping in the forums aren't concrete5 employees, we're just helping out.
spyrou replied on at Permalink Reply
spyrou
Thanks a lot mkly!!!
It seems to be working properly!
The page type of this page must be only "Blog Entry"? or I can use and another type of page like "Right Sidebar" for example?
mkly replied on at Permalink Reply
mkly
Thanks for testing it and letting me know. I'll try to wrap it up into a patch to send back to the core. It's very cool of you to do.

From the look of the code, I'm pretty sure it only looks for areas called "Main". So any page that has a "Main" I think it will take the first block from main and spit it out. You might run into trouble if the first block isn't a content block or something like that. I'd would test it out and see what happens. From what I can tell it should work.
contentwebsolutions replied on at Permalink Reply
contentwebsolutions
I changed it, but for me it's still not working. Showing all content, whatever I do. Cleared cache already...
Any ideas?

Edit: I was in the wrong template folder, but still not working the way I would expect it.

If I use the given code above, just the Titles are showing, but no text content.
peverist replied on at Permalink Reply
I get the same when applying the suggested modification - no text displayed at all rather than the description truncated to the number of characters selected when editing the page list block.

Any suggestions?
jjcdesign replied on at Permalink Reply
I had the same problem but managed to solve it by adding "echo"
echo $th->entities($th->shorten($excerpt,$truncateChars));
rdownesy replied on at Permalink Reply
Thanks for this, works great now with text, but where I have a blog entry with an image at the start of my text, it also strips that out. Any idea how to prevent the image from being removed?
crldev replied on at Permalink Reply
Brilliant. Worked a treat. Thank you.

Note, mkly corrected/edited his first post so that the code there is now correct, i.e. you need the "echo".