cancel
Showing results for 
Search instead for 
Did you mean: 

Limit Product Names

SOLVED

Limit Product Names

Hello,

 

Can someone help me with shortening the name of some products please located in a widget?

 

It is a default Magento 2 Widget located here:

 

vendor\magento\module-catalog\view\frontend\templates\product\widget\new\content\new_grid.phtml

 

I want to shorten product names shown here:

 

https://imgur.com/XxjntoJ

 

to example: Kidsaw Low Single 3ft Cabin Bed... (the - Grey part is replaced with '...')

 

If you want to see the widget from Magento Admin, it is located here:

 

Content > Pages > Edit page > Content > Insert Widget > "Catalog New Products List"

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Limit Product Names

Hi @callam_kidsaw 

 

You can use the code below to limit product name :

 

<?php /* @escapeNotVerified */ $name = $_item->getName(); ?>
<?php echo $name = strlen($name ) > 50 ? substr($name ,0,50)."..." : $name ;?>

You can override new_grid.phtml  file to your theme folder
Copy new_grid.phtml and add In your theme the same as below directory structure :

vendor\magento\module-catalog\view\frontend\templates\product\widget\new\content\new_grid.phtml


To

app\design\frontend\VendorNme\ThemeName\Magento_Catalog\templates\product\widget\new\content\new_grid.phtml

Add your changes here

 

Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!

View solution in original post

2 REPLIES 2

Re: Limit Product Names

Hi @callam_kidsaw 

 

You can use the code below to limit product name :

 

<?php /* @escapeNotVerified */ $name = $_item->getName(); ?>
<?php echo $name = strlen($name ) > 50 ? substr($name ,0,50)."..." : $name ;?>

You can override new_grid.phtml  file to your theme folder
Copy new_grid.phtml and add In your theme the same as below directory structure :

vendor\magento\module-catalog\view\frontend\templates\product\widget\new\content\new_grid.phtml


To

app\design\frontend\VendorNme\ThemeName\Magento_Catalog\templates\product\widget\new\content\new_grid.phtml

Add your changes here

 

Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!

Re: Limit Product Names

Thank you, I had the code, but was putting it in the wrong place Smiley Happy , much appreciated.