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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀