Jump to content


Photo
- - - - -

Limit No. Characters A Text Area Shows


Best Answer Sliapy , 25 December 2013 - 14:09

You can see the example of such limitation in this file \media\zoo\applications\jbuniversal\templates\catalog\renderer\item\blog\feed.php
 

$desc = JString::trim(strip_tags($this->renderPosition('description')));
$descArr = explode(' ', $desc);
$descArr_tmp = array();

foreach ($descArr as $word) {
    $word = JString::trim($word);
    if ($word) {
        $descArr_tmp[] = $word;
    }
}

if (count($descArr_tmp) > 30) {
    $descArr_tmp = array_slice($descArr_tmp, 0, 30);
    echo implode(' ', $descArr_tmp) . ' ...';
} else {
    echo implode(' ', $descArr_tmp);
}
"description" is the position with the textarea
 
"30" is the number of words Go to the full post


  • This topic is locked This topic is locked
3 replies to this topic

#1 renee

renee
  • JBZoo User
  • User rate: 0
  • posts: 72
  • topics: 26

Posted 25 December 2013 - 13:47

I'm just wondering if it is possible to have a text area that shows a limited number of characters or words?

 

It's for the teaser view of a blog type catalog template. If someone can't be bothered to edit down a section of text for the teaser intro I'd like them to be able to paste the full description text area and know that just the first X characters would show.

 

Even better than that would be if the teaser text had content then it showed but if it was empty it defaulted to X characters from the main description instead.

 

Any ideas on whether either scenario is possible natively or by customisation?


  • 0

#2 Sliapy

Sliapy
  • JBZoo User (rus)
  • User rate: 50.6
  • posts: 6393
  • topics: 15

Posted 25 December 2013 - 14:09   Best Answer

You can see the example of such limitation in this file \media\zoo\applications\jbuniversal\templates\catalog\renderer\item\blog\feed.php
 

$desc = JString::trim(strip_tags($this->renderPosition('description')));
$descArr = explode(' ', $desc);
$descArr_tmp = array();

foreach ($descArr as $word) {
    $word = JString::trim($word);
    if ($word) {
        $descArr_tmp[] = $word;
    }
}

if (count($descArr_tmp) > 30) {
    $descArr_tmp = array_slice($descArr_tmp, 0, 30);
    echo implode(' ', $descArr_tmp) . ' ...';
} else {
    echo implode(' ', $descArr_tmp);
}
"description" is the position with the textarea
 
"30" is the number of words
  • 0
[color=#aa0000]Не забывайте нажимать кнопку "Вопрос Решён" под сообщением, которое решило Вашу проблему.[/color]

#3 renee

renee
  • Topic Starter
  • JBZoo User
  • User rate: 0
  • posts: 72
  • topics: 26

Posted 25 December 2013 - 19:37

Thanks Sliapy - is this limitation imposed on the element irrespective of which view it is in (Teaser, Full etc) or can it be imposed just for one view.  It looks as though thee example above would just apply to the feed view. If so I could use just a single description field and restrict the amount of words for just the teaser view - if not it's two separate fields. But either can work.


Also thanks for replying on Christmas day - and Merry Christmas!


  • 0

#4 Sliapy

Sliapy
  • JBZoo User (rus)
  • User rate: 50.6
  • posts: 6393
  • topics: 15

Posted 25 December 2013 - 20:49

You can use it in any template - Full, Teaser - it doesn't matter.

 

Also, you can use one element (textarea) in both templates (Full and Teaser).

 

For example, in the Teaser template you can set it to the Anons position and the code in the \media\zoo\applications\jbuniversal\templates\catalog\renderer\item\*slug of the your type*\teaser.php will be 

$desc = JString::trim(strip_tags($this->renderPosition('anons')));

And in Full template you set the same element to the Text position and don't use this limitation code.


Edited by Sliapy, 25 December 2013 - 20:51.

  • 0
[color=#aa0000]Не забывайте нажимать кнопку "Вопрос Решён" под сообщением, которое решило Вашу проблему.[/color]




Click to return to top of page in style!