duanjianlu0506 2012-05-10 20:30
浏览 30
已采纳

Magento:如何分离多个属性的显示?

I am using this code to display (on the frontend) all assigned attributes of a product in Magento:

<?php if ($_product->getData('metal')): ?>  
    <?php echo nl2br($_product->getResource()->getAttribute('metal')->getFrontend()->getValue($_product )) ?>  
<?php endif; ?>

I need to separate each item with a bullet point &#149; and a break <br/>. How would I edit this code to reflect those changes? Thanks in advance.

_Sam

  • 写回答

3条回答 默认 最新

  • douerlin4366 2012-05-11 17:14
    关注

    Assuming that the above code is "working"... make this change:

    <?php echo "&#149;".nl2br($_product->getResource()->getAttribute('metal')->getFrontend()->getValue($_product ))."<br/>" ?>
    

    the . is a string concatenation operator.

    Or are you asking how to do it if the above is the HTML of a listing of products? Then this should work...

    <?php 
    $somehtml=nl2br($_product->getResource()->getAttribute('metal')->getFrontend()->getValue($_product ));
    $somehtml=explode("<br />",$somehtml);  // This ASSumes nl2br inserts <br /> between each line and this 
                                            // would lead to the behaviour you want.
                                            // see: http://php.net/manual/en/function.nl2br.php
    $somehtml=implode("<br/>
    &#149;",$somehtml);
    $somehtml="&#149;".$somehtml."<br/>
    ";
    echo $somehtml;
    unset($somehtml);
    ?>
    

    explode makes an array from a string by chopping up the string via the "<br />". implode then rejoins the the string by putting <br/> &#149; between each element. And finally, I add the bullet point to the front and br at the end. When imploding, you still must consider the "outside" of the string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?