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.

Template Questions /

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

$Content.Summary generates error: "Extra content at the end of the document"


Go to End


4 Posts   5040 Views

Avatar
david_nash

Community Member, 55 Posts

5 June 2009 at 1:14pm

Hello

I'm not sure if it's something I've doing wrong or if it's a bug that I've come across. I'm hoping for some advice.

On my homepage I am showing the latest news:

<% control PublishedNews(5) %>
	<div class="container">
		<h3><a href="$Link">$Title.XML</a></h3>
		<p class="date">$Date.Long</p>
		<div>$Content.Summary(20) <a href="$Link">more...</a></div>
	</div>
<% end_control %>

PublishedNews() is a function in HomePage.php that does a DataObject::get() on news items that have been published.

But the above template code generates this error:
"[Warning] SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 2: parser error : Extra content at the end of the document"

I believe it's because there's a link in the content that extends past the 20 characters, and the XML parser is seeing this and choking.

What could I do to prove this theory? What can I do to get around this?

I want to have HTML formatting and links in the news summary. As far as I can see, Summary() is the only method that will give me HTML.

Thanks!

Avatar
david_nash

Community Member, 55 Posts

5 June 2009 at 1:17pm

Update: I don't think it's the character limit, it seems that no matter how I use Content.Summary I get the same error.

Avatar
Sean

Forum Moderator, 922 Posts

5 June 2009 at 4:07pm

This has been an issue for a while.

Here's a ticket for it in the SS open source tracker: http://open.silverstripe.org/ticket/3157

It seems like the solution would be to create a new function called html2array() and use that instead of xml2array() on HTMLText::Summary(). html2array() would do something like this:

$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML($html);
$xml = simplexml_import_dom($doc);

This idea was found at http://drewish.com/node/90

I'll update the ticket with this snippet of code.

Cheers,
Sean

Avatar
david_nash

Community Member, 55 Posts

5 June 2009 at 5:07pm

Thanks Sean.

Does that go inside my site code or do I need to edit the core? Could you point me in the right direction?

Say I call $Content.Summary(20). Is it giving me 20 characters of RAW HTML or 20 chars of whatever would be outputted?

And does that method produce valid HTML?

Thanks again!