Jump to content

Using |replace two replace two items in one line?


-M-

Recommended Posts

I know how to use |replace: for one line, but what if you want to replace two things from 1 line?

 

For example I have the line:

 

This is before - main text - And text after

 

So far I only know how to remove one part, for example by using:

 

{$variable|replace:'This is before - ':''}

 

But I am unable to remove the '- And text after' also in one go.

 

I tried a few (foolish) things, by adding:

 

,'content two'

and

|| in between

 

Like I said; probably foolish, but wanted to try it before I asked for help.

 

Thank you in advance.

Link to comment
Share on other sites

it's probably worth mentioning that the order you put these replaces in can matter - not in the above case as you're just removing text, but if you were genuinely replacing some text with other text, then you will need to take care...

 

e.g if the string is "brian has basic knowledge of Smarty!" and you try...

 

{$variable|replace:'basic':'some'|replace:'some':'no'}

it will change the string to "brian has no knowledge of Smarty!" - so it performs the first replace (changes basic to some), and then performs the second replace on the modified string (changing some to no), not the original.

 

as I said, you're not currently trying to do this, but thought it worth explaining in case you try to do this in the future. :idea:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated