Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Using ampersand and FirstSentence

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

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

Page: 1
Go to End
Author Topic: 1836 Views
  • gakenny
    Avatar
    Community Member
    153 Posts

    Using ampersand and FirstSentence Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Using ampersand and FirstSentence Link to this post

    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?

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: Using ampersand and FirstSentence Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Using ampersand and FirstSentence Link to this post

    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.

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: Using ampersand and FirstSentence Link to this post

    Thanks Will - I'll give that a shot.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Using ampersand and FirstSentence Link to this post

    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

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: Using ampersand and FirstSentence Link to this post

    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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Using ampersand and FirstSentence Link to this post

    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

    1836 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.