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.

Archive /

Our old forums are still available as a read-only archive.

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

Using ampersand and FirstSentence


Reply


8 Posts   1999 Views

Avatar
gakenny

Community Member, 153 Posts

6 October 2007 at 8:51pm

Hello,

The first sentence of a Content field contains an ampersand (&). When using the special variable FirstSentence ($Content.FirstSentence), I get an XML Parsing error in FireFox at this point:
XML Parsing Error: not well-formed

What can I do to get around this?

Cheers,

Gary

Avatar
Ingo

Forum Moderator, 801 Posts

7 October 2007 at 1:15am

FirstSentence is not safe to use with XML/HTML-markups, as it just parses for dots, and doesn't respect any opened tags. needs some refactoring (probably by using simplexml and falling back to dot-parsing in case of invalid input-markup) - anybody keen? :)

Avatar
gakenny

Community Member, 153 Posts

7 October 2007 at 4:16pm

Hi Ingo,

Thanks for the reply. In this case, the ampersand is used to seperate two peoples names. Just displaying $Content in the code works fine - it's only when I use FirstSentence. Is there a 'quick' fix to make this work for this situation?

Cheers,

Gary

Avatar
Willr

Forum Moderator, 5513 Posts

7 October 2007 at 4:48pm

you could you Summary() to generate 1 sentence and I believe Summary will render all the html and things like ampersand correctly.

Or you could turn off the Content Negotiator using ContentNegotiator::disable() in the _config.php and remove the XML header at the top of Page.ss and that will stop sending the template as super strict xml (which inforces things like Parsing errors) and instead send the page as normal text/html which will let errors like that through.

Avatar
gakenny

Community Member, 153 Posts

7 October 2007 at 4:58pm

Thanks Will - I'll give that a shot.

Avatar
Ingo

Forum Moderator, 801 Posts

8 October 2007 at 1:18am

yeah Summary() seems to be the only function who does some checking for closing tags.
i've added warnings to the phpdocs of the other stripping-functions

Avatar
gakenny

Community Member, 153 Posts

8 October 2007 at 5:22pm

Hello,

I found that this function also caused the same issue. In the end, I modified my _config.php file to include:
ContentNegotiator::disable()

And this has resolved the issue for now.

Kind regards,

Gary

Avatar
Sean

Forum Moderator, 922 Posts

8 October 2007 at 5:30pm

Edited: 08/10/2007 5:33pm

I find the summarisation functions are a little funny. Sometimes they add <br /> tags after line breaks. Is this caused by new lines - \n, perhaps?

I think what we need to do is review all these methods, there are a lot of them in there. Some of them do relatively the same thing, and we can combine them into a single method. Having a unified function that does more would probably be nicer.

For example: $Content.Summary(26, false) to limit Content at 26 words, without stripping HTML tags. Not passing true outputs non-stripped out HTML in the summary. This function would also carefully make sure that the returned summary is XML compliant, and doesn't have any strange <br /> line breaks either that some of the current summary methods have.

Ideas?

Sean