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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

escaping HTML tags in page title


Go to End


2 Posts   2898 Views

Avatar
Anatol

126 Posts

20 April 2009 at 2:44pm

Hi,

I'm looking for a way to allow escaped HTML tags in the page title. It's no problem to use $Title.XML in the template to escape the tags properly, but if I have a title like "<p> The Paragraph Tag" it confuses the site tree in the CMS. How can I escape HTML titles in the CMS site tree?

I can enter "&lt;p&gt; The Paragraph Tag" into the navigation label field and it works - but it's always nice to have escapes done automatically. And this could also be a possible error source if a client uses a page title with a '<' or '>' character.

Cheers!
Anatol

Avatar
Carbon Crayon

Community Member, 598 Posts

20 April 2009 at 9:12pm

Edited: 20/04/2009 9:13pm

Hi Anatol

I think you could use onBeforeWrite() to escape the string using htmlentities() before writing, something like this:

function onBeforeWrite(){

$this->Title = htmlentities($this->Title);

return Parent::onBeforeWrite();
}

Havn't tried it but something like that should work :)