首页 > 解决方案 > 如何在列表中仅保留 $product.description_short 的第一段?

问题描述

我只想在类别中保留产品描述的第一段。

例子:<p>This is a pretty good description.</p><p>The rest of the description, even if it's cool to I don't want it.</p>

至 :<p>This is a pretty good description.</p>

这是 product-list.tpl Prestashop (1.6) 中的默认代码:

<p class="product-desc" itemprop="description">
   {$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}
</p>

这是我在 product-list.tpl Prestashop (1.6) 中尝试的默认代码:

<p class="product-desc" itemprop="description">
   {assign var $newdescription = $product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}
   {preg_replace('(?<=<\/p>)\s+<p>.*','',$newdescription)}
</p>

标签: regexprestashopsmartyprestashop-1.6

解决方案


{$_shorten = explode('</p>', $product.description_short)}
// with valid html tags
{$_shorten.0|cat:'</p>'}
// or if you want to strip tags:
{$_shorten.0|strip_tags}

推荐阅读