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:
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"
Solved! Go to Solution.
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
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
Thank you, I had the code, but was putting it in the wrong place , much appreciated.