-M- Posted November 2, 2015 Share Posted November 2, 2015 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. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 2, 2015 Share Posted November 2, 2015 what about this {$variable|replace:'This is before - ':''|replace:' - And text after':''} 1 Quote Link to comment Share on other sites More sharing options...
-M- Posted November 3, 2015 Author Share Posted November 3, 2015 Man, I tried several things, but mainly resulting in a blank page. Things always seem simple after you see how they are done. Thanks sentq! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 3, 2015 Share Posted November 3, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
-M- Posted November 3, 2015 Author Share Posted November 3, 2015 Thanks for explaining it more thoroughly Brian. I bookmarked this page for future reference as well. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.