3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1460 Views |
-
[Solved] limitcharacters is stripping html

13 July 2010 at 4:03am Last edited: 16 July 2010 4:49am
I have 3 featured columns on the homepage of a project I am working on. I am limiting the number of characters it returns for consistency. My code is as follows.
$Content.LimitCharacters(285, ...)
For whatever reason it is returning the content without the p tags which is the only html in the content. So the first 2 paragraphs become one and it is quite ugly.
I need those p tags!!!
Any ideas?
-
Re: [Solved] limitcharacters is stripping html

13 July 2010 at 9:17am Last edited: 13 July 2010 10:14am
Well...
It does say in the documentation (and quite clearly in the php code if you were to open '\sapphire\core\model\fieldtypes\HTMLText.php') of the function that it will strip tags. I can see why this is required due to limiting the number of words... if you counted words within script tags you would get a bad result. And the logic of maintaining the html and counting words id not that easy to do.
You could write your own function if you want to only count words not in tags. As a quick and dirty solution I might use...
1) replace your </p> & <br> with something like {ENDLINE}
2)do the same logic as LimitCharacters
3)Replace {ENDLINE} with <br>Barry
-
Re: [Solved] limitcharacters is stripping html

13 July 2010 at 9:40am
But I don't want to only count words and not in tags. I want it to return the words and the tags.
-
Re: [Solved] limitcharacters is stripping html

13 July 2010 at 10:03am
If I misunderstood I'm sorry...
Regarding the function... it clearly strips the tags and the reason for doing so is obvious... it is not easy to count the number of words while there are tags in there... really it shouldn't take more than 5 minutes to create the function yourself based on my simple suggestion... why not do that?
You can raise this as a ticket on open.silverstripe.org as an enhancement... but it is my very strong suspicion it would be quicker to do it yourself
Or how about doing it yourself AND sharing it with us?
Barry
| 1460 Views | ||
|
Page:
1
|
Go to Top |


