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

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路