0

Would you guys recomend me a way i could make the read more button appear only if the description has a certain ammount of characters only?

{if isset($product) && $product->description }
    <!-- full description -->
    <div id="idTab1"  style="overflow:hidden;height:250px;font-family:avantgarde-book;font-size:12px;line-height:14px;">{$product->description}</div>
    <input id="button" type="button" style="margin-top:5px;font-size:12px;color:white;font-family:avantgarde-book; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar +" onclick="showMore()"> 
            <input id="button2" type="button" style="margin-top:5px;display:none;font-size:12px;color:white;font-family:avantgarde-book; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar -" onclick="showLess()">

{/if}

i got this code so far and its working fine but the button appears even when its too short description, so i want to make the condition to show of only when the description is XXX number of characters long or more...

Zavior
  • 6,412
  • 2
  • 29
  • 38
Marcosdro
  • 19
  • 1
  • 7
  • 1
    How does this relate to Java? – Duncan Jones Feb 16 '14 at 18:34
  • 1
    sidenote: save some bandwidth, it might be a good idea to put your inline css into your css file – Lawrence Cherone Feb 16 '14 at 18:38
  • You can use [strlen](http://php.net/strlen) function in PHP to check the product description length. If it exceeds the limit you can cut the string using [substr](http://php.net/substr) and append a "Read more" button/link whatever. Also see http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-chara – ggirtsou Feb 16 '14 at 18:39

1 Answers1

1

This is fairly easy since prestashop uses smarty.

Let's say you want to limit your description to 200 chars and after that display read more button

You can use count_characters. Here is a example:

{if isset($product) && $product->description }
        {* full description *}
        <div id="idTab1"  style="overflow:hidden;height:250px;font-family:avantgarde-book;font-size:12px;line-height:14px;">{$product->description}</div>
        {if $product->description|count_characters:true > 200 }
            <input id="button" type="button" style="margin-top:5px;font-size:12px;color:white;font-family:avantgarde-book; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar +" onclick="showMore()"> 
            <input id="button2" type="button" style="margin-top:5px;display:none;font-size:12px;color:white;font-family:avantgarde-book; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar -" onclick="showLess()">
        {else}
            {* don't display anything *}
        {/if}

{/if}

You can read about count_characters and about it's attributes from here

http://www.smarty.net/docsv2/en/language.modifier.count.characters.tpl

P.S right way to display something as a comment in smarty syntax is to display it between these tags {* *}

BR's

(if this helps you dont forget to accept it :) )

user2831723
  • 832
  • 12
  • 25