Limiting Text Volume
Permalink
I am quite new to PHP..
Is it possible to set the limit to Text Volume in a block, using PHP?
Is it possible to set the limit to Text Volume in a block, using PHP?
Concrete5 also has a bunch of "helpers" for stuff like this. Just browse through c5root/concrete/helpers/ and explore what's available.
Here's c5's built in function for shortening text:
Here's c5's built in function for shortening text:
$numberOfChars=255; $textHelper = Loader::helper("text"); echo $textHelper->shortText( $myLongText, $numberOfChars );
griebel,
It works in the fixed contents but I guess I need to arrange this code when appling to the editable contents like the following part in the theme.
Thanks anyway!
Tony,
Where should I put this?
Actually, I put it into the abovementioned code as it is but nothing's happened..
Could you give me Further advise, please?
It works in the fixed contents but I guess I need to arrange this code when appling to the editable contents like the following part in the theme.
<? $a = new Area('photo'); $a->display($c); ?>
Thanks anyway!
Tony,
Where should I put this?
Actually, I put it into the abovementioned code as it is but nothing's happened..
Could you give me Further advise, please?
it has pretty much exactly the same interface as griebel's function (except it is a method of an object instead of a function). As long as you're using concrete 5 it should work.
I'm not familiar with PHP at all...
When I use the code you told me, I put it in the new Area code like the following. Is this correct?
When I use the code you told me, I put it in the new Area code like the following. Is this correct?
<? $a = new Area('article'); $a->display($c); $numberOfChars=255; $textHelper = Loader::helper("text"); echo $textHelper->shortText( $myLongText, $numberOfChars ); ?>
ok. The $myLongText is a variable that I was assuming you'd swap out with a variable holding the text you wanted to truncate.
For what you're doing, I'd really recommend running the shortText function on an actual block rather than the area, simply because it doesn't make sense to truncate the markup of most other blocks since it will render them useless. You'd do this by creating a custom template for a block, which in your case will probably be the content block.
i'm attaching a file to this post. unzip it and copy the file to yourConcreteRoot/blocks/content/templates/
Then after adding a content block to that area, click it, select the "set custom template", and select this new shortText view.
(Note that I'm also running strip_tags in that template, cause otherwise it might chop the text off in the middle of an html tag)
For what you're doing, I'd really recommend running the shortText function on an actual block rather than the area, simply because it doesn't make sense to truncate the markup of most other blocks since it will render them useless. You'd do this by creating a custom template for a block, which in your case will probably be the content block.
i'm attaching a file to this post. unzip it and copy the file to yourConcreteRoot/blocks/content/templates/
Then after adding a content block to that area, click it, select the "set custom template", and select this new shortText view.
(Note that I'm also running strip_tags in that template, cause otherwise it might chop the text off in the middle of an html tag)
It works well!
I'm wondering that if it's possible to set a custom template, maintaining css code defined in the theme.
I'm wondering that if it's possible to set a custom template, maintaining css code defined in the theme.
10 is the number of characters (your limit)