ajaxsoap Posted March 18, 2017 Share Posted March 18, 2017 Hi, I would like to ask how do you remove or should I say reverse truncate or replace a character before ":" or to the left of ":"on a product name? Ex. TOPS: TOPS Acrylic Emulsion Clear Gloss I would like it to display it like this: TOPS Acrylic Emulsion Clear Gloss I tried to this code {$product.name|truncate:20:' ':true:true|escape:'htmlall':'UTF-8'} but the output is this: TOPS: TOP ear Gloss What should be the proper way to accomplish this? Thanks in advance! Marvin Link to comment Share on other sites More sharing options...
Guest Posted March 18, 2017 Share Posted March 18, 2017 I don;t know about the coding, but can I ask why Do you need the ":" to stay there or can you not just delete it in the title? If it is volume, you could export to CSV, lose the characters in Excel (I can show the function for that) then upload again Link to comment Share on other sites More sharing options...
rictools Posted March 19, 2017 Share Posted March 19, 2017 I'm not sure, I think first you must search for : to get it's position in the string, then, if it's at position 5, you know you have to remove the first 6 characters. Link to comment Share on other sites More sharing options...
ajaxsoap Posted March 19, 2017 Author Share Posted March 19, 2017 Thanks to all your responses! Really appreciate it! The string that is to the left of ":" is actually a sub category were the product is belong to, the way I inputted product name is this "subcategory: product name" but I want it to display on front office only the product name. The rational behind this decision is because of the way prestashop displayed it in shopping cart summary, by default only the product name appear on the cart not with a subcategory. Instead of revising the cart summary template I decide to revise only the product list template. I wanted to display in the product list only the product name without the subcategory ("remove:"product name) but in the cart summary the normal product name with subcategory (subcategory:product name). I hope that clarifies my intention. I've came across this thread on smarty forum to use a regex replace: {$address|regex_replace:"/(.*@)/":"@"} But the respondent suggested not to put the regex in the template but create a modifier. I haven't look on how to create modifier yet. Thanks Link to comment Share on other sites More sharing options...
rictools Posted March 19, 2017 Share Posted March 19, 2017 You can put it in the tpl-files if you repeat this work after a prestashop update. Link to comment Share on other sites More sharing options...
ajaxsoap Posted March 19, 2017 Author Share Posted March 19, 2017 I'm happy to report that I've managed to solve my problem! Here's the code snippet: {$product.name|regex_replace:"/\b.*[^.][^:]:/":" "|escape:'htmlall':'UTF-8'} I've played around on regex 101 to explore any possibilities. Since my goal is to display only the characters on the right side, first, I've formulate a regex selecting to the right of ":", but since i'm using regex_replace, I've reversed it to select to the left and replace it with " ". Last question, do I have to create a modifier for this? Thanks to all of you who responded! Cheers! Link to comment Share on other sites More sharing options...
rictools Posted March 19, 2017 Share Posted March 19, 2017 How often do you update? If not every time it's no problem to make a notice about what you changed and in what files and repeat it after an update. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now