Jump to:

520 Posts in 248 Topics by 263 members

Content Editor Discussions

SilverStripe Forums » Content Editor Discussions » Can't Use & Symbol?

Forum for content editors and CMS users.

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

Page: 1 2
Go to End
Author Topic: 3181 Views
  • jfusco
    Avatar
    Community Member
    52 Posts

    Can't Use & Symbol? Link to this post

    If I put the & symbol into the content of an article page, the system freaks out (v2.2.3). This is what I get:

    XML Parsing Error: not well-formed
    Location: http://www.unclebubby.com/wavs2/action-adventure/
    Line Number 248, Column 43:         <li class="newsSummary">In a dystopic & crime ridden Detroit, a terminally wounded
    ---------------------------------------------------------------^


    I case it doesn't line up right, the ^ is pointing to the & symbol. Why does it care what's in my text field?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Can't Use & Symbol? Link to this post

    It doesn't care but '&' isnt valid xhtml/xml so what you need to do is add .XML to your variable in the template. (Assuming you use something like Summary...

    Another option is to remove the xml prolog from the top of your Page.ss template, because it'll probably get broken again.

    What's happening here is that the page is rendering invalid xhtml in a strict xml page, it's not really related to the system.

  • JasonS
    Avatar
    Community Member
    14 Posts

    Re: Can't Use & Symbol? Link to this post

    & is invalid xhtml. Instead you can replace it with &amp; This is the ascii character code for &.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Can't Use & Symbol? Link to this post

    @JasonS Normally you don't need to do this yourself for the stuff you put in a HtmlEditorField.

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: Can't Use & Symbol? Link to this post

    As more clarification, it works fine in the title field but freaks out if it's in the content field. I get that it's invalid XML, I just don't get why it's an issue coming out of a text field that it should only be interpreting as HTML, not XML, right?

    @dio5 - My template is straight out of the tutorials. Where, specifically, would I need to make changes?

    @JasonS - The code behind the field actually uses &amp;

    <p align="center">&nbsp;In a dystopic&nbsp;&amp; crime ridden Detroit, ...

    The workaround is to spell it out, obviously.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Can't Use & Symbol? Link to this post

    Just had a look at http://www.unclebubby.com/wavs2/action-adventure/ - saw you replaced it with 'and'.

    I don't know what's in the tutorials, so if you could show us yr template code? It's probably the method you use on the holder page to display just a part of the text that's causing it. But if the source code of that page shows &amp; as well?!

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: Can't Use & Symbol? Link to this post

    Main Page.ss

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
       <head>
          <% base_tag %>
          $MetaTags
          <link rel="stylesheet" type="text/css" href="mysite/css/layout.css" />
          <link rel="stylesheet" type="text/css" href="mysite/css/typography.css" />
          <link rel="stylesheet" type="text/css" href="mysite/css/form.css" />
       </head>
       <body>
          <div id="Main">
             <ul id="Menu1">
                <% control Menu(1) %>
                   <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
                <% end_control %>
             </ul>
             <div id="Header">
                $SearchForm
                <h1>$Title</h1>
             </div>
             <div id="ContentContainer">
                $Layout
             </div>
             <div id="Footer">
                <span>Visit <a href="http://www.silverstripe.com" title="Visit www.silverstripe.com">www.silverstripe.com</a>; to download the CMS</span>
             </div>
          </div>
          $SilverStripeNavigator
       </body>
    </html>


    ArticleHolder.ss

    <% include Menu2 %>
    <div id="Content" class="typography">      
       $Content
       <ul id="NewsList">
          <% control Children %>
             <li class="newsDateTitleSmall"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
             <li class="newsDateTitleSmall">Released in $Date.Year</li>
             <li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
          <% end_control %>
       </ul>
    <center>For more information about any of the movies, shows or actors you see here,
    <br>visit <a href="http://www.imdb.com" target="_blank">The Internet Movie Database (IMDB)</a>
    <br><strong><a href="mailto:jfuscoDELETETHECAPS@gmail.com?subject=Wav Archive Feedback">Click here to send email to Uncle Bubby</a></strong></center>
    </div>


    ArticleHolder.php

    <?php
    /**
    * Defines the ArticleHolder page type
    */
    class ArticleHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    static $icon = "tutorial/images/treeicons/news";
    static $allowed_children = array('ArticlePage');
    }

    class ArticleHolder_Controller extends Page_Controller {
    function rss() {
    $rss = new RSSFeed($this->Children(), $this->Link(), "The coolest news around");
    $rss->outputToBrowser();
    }
    function init() {
    RSSFeed::linkToFeed($this->Link() . "rss");   
    parent::init();
    }}

    ?>

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Can't Use & Symbol? Link to this post

    Right,

    what if you replace

    $Content.FirstParagraph

    with

    $Content.FirstParagraph.XML

    in ArticleHolder.ss

    3181 Views
Page: 1 2
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.