3397 Posts in 978 Topics by 854 members
|Go to End|
5 June 2009 at 1:14pm
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>$Content.Summary(20) <a href="$Link">more...</a></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.
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.
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;
$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.
5 June 2009 at 5:07pm
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?
|Go to Top|