duanfangbunao36970 2014-02-16 18:33
浏览 36
已采纳

prestashop:如果描述长于XXX个字符,则在产品描述中显示更多内容

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...

  • 写回答

1条回答 默认 最新

  • duan5731 2014-02-16 23:07
    关注

    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 :) )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题