PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to keep only the first paragraph of $product.description_short in a listing?

 June 30, 2022     prestashop, prestashop-1.6, regex, smarty     No comments   

Issue

I want to keep only the first paragraph of product description in categories.

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

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

This is the default code in product-list.tpl Prestashop (1.6):

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

This is what I tried default code in 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>

Solution

{$_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}


Answered By - r_a_f
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing