M
M
Michael2017-10-15 21:31:07
opencart
Michael, 2017-10-15 21:31:07

Limit number of characters in Opencart 3 product name?

https://github.com/opencart/opencart/blob/master/u...
199 line did this:'name' => $result['name'],

'name' => utf8_substr(strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), 0, 25) . '..',

but short names have unnecessary dots added.
Help me write a condition so that only the names > n characters would be abbreviated.
I found such a solution on the net, is it possible to register it in the controller or in the template now (twig)?
<?php if( strlen( $product['name'] ) < 30 ) { echo $product['name']; } else { echo mb_substr( $product['name'],0,20,'utf-8' )."..."; } ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bugsbunnyua, 2018-08-03
@bugsbunnyua

Interested in the reverse action, how to make the name of the product completely?

Z
zoozag, 2017-10-16
@zoozag

You can in the controller.
In twig it is also possible, see Slice
The only question is how he perceives the Cyrillic.
It's better not to cut them at all, but to hide them through CSS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question