Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Issue displaying blog excerpt


Go to End


4 Posts   2781 Views

Avatar
swoophoop

Community Member, 2 Posts

15 July 2015 at 5:23am

Edited: 15/07/2015 5:24am

Hi all,

I'm trying to use the blog module and I've got it installed fine, it works, I can create new posts, edit them, publish them etc. However, I'm having some trouble formatting the blog excerpt. I've modified BlogPost.php to increase the excerpt word count from 30 to 75, but the excerpt displays rather bizarrely on the site, with a <br> tag every 10 words. Is there anything I can do to stop this happening as it looks terrible! This screenshot shows what I mean:

Avatar
Pyromanik

Community Member, 419 Posts

15 July 2015 at 10:07pm

Edited: 15/07/2015 10:31pm

A couple of things:

1. Never ever edit php files that aren't yours.
The correct way to alter the summary snippit is to copy the template file into an equivalent (preserve template dir structure) higher priority directory (in either the theme or your project), then edit that copy. You use the variable $Excerpt(75) or $Content.Summary(75) from your template to get what you want. Don't forget to ?flush afterwards.
c.f. https://github.com/silverstripe/silverstripe-blog/blob/master/templates/Includes/PostSummary.ss#L18

2. Check your entered content.
It probably has a lot of line returns in it. This is common particularly if you have copied and pasted the copy from elsewhere. The summary function strips formatting, and runs through nl2br from memory, so that result is normal. Formatting into proper paragraphs should rectify the issue.

Avatar
swoophoop

Community Member, 2 Posts

17 July 2015 at 2:46am

Thanks for the reply. I've changed to php file back to the original and created a new template. I've retype the articles within the CMS, created new articles in the CMS and haven't copied any text into the articles, yet I'm still getting the same response, although the word length is now varying slightly, between 10-14 words. I'm starting to wonder if this is designed to allow for the featured image to sit alongside the blog summary, limiting the line length so the text fits nicely alongside?

Avatar
Pyromanik

Community Member, 419 Posts

18 July 2015 at 12:04am

There's no accurate way to know how long a rendered piece of text will be, so no.
Are you sure you're editing the right template? Making some test data in it so you can tell easily is sometimes a good idea.
Something like FirstParagraph would give the behaviour you're describing.