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.

Template Questions

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


Reply

4 Posts   3786 Views

Avatar
david_nash

5 June 2009 at 1:14pm Community Member, 55 Posts

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

5 June 2009 at 1:17pm Community Member, 55 Posts

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

5 June 2009 at 4:07pm Forum Moderator, 921 Posts

This has been an issue for a while.

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

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 [url]http://drewish.com/node/90[/url]

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

Cheers,
Sean

Avatar
david_nash

5 June 2009 at 5:07pm Community Member, 55 Posts

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!