Prestashop 1.7 add <br> special character tag in category name but invalid , how to split string in menu navigation nav?

孤者浪人 提交于 2020-07-23 06:31:18


A lot of people are having a similar problem for adding a hashtag in the product name. I am trying to add a
tag ( html line break ) in the category name. I have put "Category
name" for example, it won't work. The character validation is there for security measures, it makes sense.

So I have tried to overwrite the file "Validate.php" , as explained on another topic by redefining the isCatalogName function like so :

class Validate extends ValidateCore

    public static function isCatalogName($name)
        // simple test
        return !preg_match('/[]/i', $name);

now I should be able to put a hashtag like # , or <br /> like I wanted, but still get the error.

I have tried different ways :

  • overwriting only the file "Validate.php"
  • overwriting Validate.php, but also Category.php and CMSCategory.php where the function "isCatalogName($name)" is called and removing the validation in these files.
  • I cleared cache in back-end and also var/cache files to be sure each time, logged out / logged in administration every time. Refreshed browser cache / Changed browser too !

Any ideas on how to have a split string ( 2 lines menu navigation link ) in the category name on Prestashop 1.7 ?


Well after looking around and asking on the Prestashop forums, I've been told there is no easy-straightforward-hack-free solution to achieve this. Because apparently the name chosen for the category is used to construct the url. This would mean editing many core files just to put a special character via the back-end>categories fields, which is illogic.

So I just hardcoded this into the file modules\ps_mainmenu\*ps_mainmenu.tpl* : it works for my case.

 {* {$node.label} *}

               {if $node.label|strstr:"and"}
                  {assign var="teststring" value=$node.label}
                  {assign var="testsplit" value="and"|explode:$teststring}
                  {$testsplit[0]} <br/> and {$testsplit[1]}
                  {elseif $node.label|strstr:","}

                  {if substr_count($node.label, ",") > 1 }

                    {assign var="teststring" value=$node.label}

                    {assign var="label" value=","|explode:$teststring}

                    {$label[0]},<br/>{$label[1]}, {$label|@end}


I'm sure someone PHP/Smarty savy could do this in a few lines and much nicer ( let me know please! ) but it works for me. (adding <br/> in some cases)