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.

Template Questions

First character of paragraph in <div>


5 Posts   1389 Views


16 January 2010 at 11:55pm Community Member, 153 Posts


I am wanting to do some special formatting on the very first character of the very first paragraph on the Homepage of my site by including this within a <div>.

My issue is how to split this first character from the remaining characters from the $Content variable.

I have created a couple of functions and added these to my HomePage.php file:
function ContentFirstCharacter() {
return ($Content[0]);

function ContentLastCharacters() {
return (substr($Content,1));

It appears that the $Content variable is not available and these functions return blanks. I have tried to pass the variable as a parameter with no success either.

Can anyone give me a push in the right direction?

Many thanks,



17 January 2010 at 1:07am Community Member, 243 Posts

To manipulate the content you need to use $this->Content; in the PHP, $Content is just for the templates.


17 January 2010 at 8:20am Community Member, 153 Posts

Hi Pigoen,

Thanks for the reply. I did try this and I was receiving a '<' from ContentFirstCharacter. After a sleep, it seems obvious that this would be the first character of the HTML code included in the $Content variable (and referenced in PHP by $this->Content.

Can I strip the HTML from this variable and reference the text only in my PHP functions?

Kind regards,



17 January 2010 at 10:35am Community Member, 243 Posts

Ah, of course it would return a '<'.

You want to do this:

$content = $this->dbObject('Content')->NoHTML();

That will give you the HTML stripped content.


17 January 2010 at 6:46pm Community Member, 153 Posts

Thanks Pigeon,

That cracked it. I had just tried the following with the same result:
$content = strip_tags($this->Content)

However, I have reverted to your code as this utilises the functions within SilverStripe.

Thanks for your help!