3215 Posts in 848 Topics by 811 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1172 Views |
-
First character of paragraph in <div>

16 January 2010 at 11:55pm
Hello,
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,
Gary
-
Re: First character of paragraph in <div>

17 January 2010 at 1:07am
To manipulate the content you need to use $this->Content; in the PHP, $Content is just for the templates.
-
Re: First character of paragraph in <div>

17 January 2010 at 8:20am
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,
Gary
-
Re: First character of paragraph in <div>

17 January 2010 at 10:35am
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.
-
Re: First character of paragraph in <div>

17 January 2010 at 6:46pm
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!
Cheers,
Gary
| 1172 Views | ||
|
Page:
1
|
Go to Top |


