cancel
Showing results for 
Search instead for 
Did you mean: 

Limit of Product Name in Product Catalog Magento 2.3

SOLVED

Limit of Product Name in Product Catalog Magento 2.3

How and where i can override to change the limit of characters in product name in catalog page?

Like i have a product name as ABCDEFGHIJK and this took like 2 lines of words

i want to be shown only ABCD... for an example

 

 

Can someone help me?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Limit of Product Name in Product Catalog Magento 2.3

Hello @eCom_Microware 

 

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/template...

 

<?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>

you need to change here:-
<?php /* @escapeNotVerified */ $name = $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
<?php echo $name = strlen($name ) > 50 ? substr($name ,0,50)."..." : $name ;?>

if you are using any theme then you need to change into

 

app/design/frontend/YourTHemePackageName/ThemeName/Magento_Catalog/templates/product/list.phtml

 

hope it will help you


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

15 REPLIES 15

Re: Limit of Product Name in Product Catalog Magento 2.3

Hello @eCom_Microware 

 

you need to apply below css for this

p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 75ch;
}

you need to add your class, hope it will help you.

 

If works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Limit of Product Name in Product Catalog Magento 2.3

Hi thanks for your quickly reply

 

There is a way to make the maximum lines to 2?

 

image.png

Above is inserting your code.

 

I want something like this

image.png

Re: Limit of Product Name in Product Catalog Magento 2.3

@eCom_Microware 

i am not able see your screenshot, please share via some onlline tool

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Limit of Product Name in Product Catalog Magento 2.3

https://imgur.com/a/QhHX4uD

You can see both images in imgur

 

The first one is with your code

 

The second one is the way i need

Re: Limit of Product Name in Product Catalog Magento 2.3

Hello @eCom_Microware 

 

you can just adjust max width 

 

hope it will help you, if works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Limit of Product Name in Product Catalog Magento 2.3

Over 186px nothing changes, because using white-space nowrap, the text only appears in one line.

 

I Think using css is impossible to do that, maybe override a file in cores files

Re: Limit of Product Name in Product Catalog Magento 2.3

Hello @eCom_Microware 

 

 

you need to do using php if you need into two lines

 

$out = strlen($in) > 50 ? substr($in,0,50)."..." : $in;

where you need to increase 50 to whatever you wants.

 

hope it will help you, if works then mark as a solution. 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Limit of Product Name in Product Catalog Magento 2.3

Thanks again,

i know that, but i dunno where to insert this code to work properly, can u help me?

Re: Limit of Product Name in Product Catalog Magento 2.3

Hello @eCom_Microware 

 

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/template...

 

<?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>

you need to change here:-
<?php /* @escapeNotVerified */ $name = $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
<?php echo $name = strlen($name ) > 50 ? substr($name ,0,50)."..." : $name ;?>

if you are using any theme then you need to change into

 

app/design/frontend/YourTHemePackageName/ThemeName/Magento_Catalog/templates/product/list.phtml

 

hope it will help you


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer