Jump to content

How to remove all characters to the left of a ":"


ajaxsoap

Recommended Posts

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...