Jump to:

3432 Posts in 1025 Topics by 865 members

Template Questions

SilverStripe Forums » Template Questions » $Content.Summary generates error: "Extra content at the end of the document"

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

Page: 1
Go to End
Author Topic: 3723 Views
  • david_nash
    Avatar
    Community Member
    55 Posts

    $Content.Summary generates error: "Extra content at the end of the document" Link to this post

    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!

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: $Content.Summary generates error: "Extra content at the end of the document" Link to this post

    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.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: $Content.Summary generates error: "Extra content at the end of the document" Link to this post

    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

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: $Content.Summary generates error: "Extra content at the end of the document" Link to this post

    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!

    3723 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.