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:33:22

问题


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 :

<?php
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 ?


回答1:


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}
                    

                  {/if}

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)



来源:https://stackoverflow.com/questions/62854647/prestashop-1-7-add-br-special-character-tag-in-category-name-but-invalid-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!