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.

Content Editor Discussions /

Forum for content editors and CMS users.

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

Can't Use & Symbol?


Go to End
Reply


13 Posts   3367 Views

Avatar
jfusco

Community Member, 52 Posts

27 January 2009 at 1:40am

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?

Avatar
dio5

Community Member, 501 Posts

27 January 2009 at 4:00am

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.

Avatar
JasonS

Community Member, 14 Posts

27 January 2009 at 8:42am

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

Avatar
dio5

Community Member, 501 Posts

27 January 2009 at 8:45am

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

Avatar
jfusco

Community Member, 52 Posts

27 January 2009 at 9:26am

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.

Avatar
dio5

Community Member, 501 Posts

27 January 2009 at 9:32am

Edited: 27/01/2009 9:33am

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?!

Avatar
jfusco

Community Member, 52 Posts

27 January 2009 at 10:22am

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" xml: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();
}}

?>

Avatar
dio5

Community Member, 501 Posts

27 January 2009 at 10:39am

Edited: 27/01/2009 10:41am

Right,

what if you replace

$Content.FirstParagraph

with

$Content.FirstParagraph.XML

in ArticleHolder.ss

Go to Top