|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
qgoodlike Smarty n00b
Joined: 17 Aug 2017 Posts: 3
|
Posted: Thu Aug 17, 2017 1:12 pm Post subject: Please help! Replace |
|
|
How to make multiple values "replace", for example:
{$variable|replace:'TEXT':'REPLACEDTEXT'}
TEXT to REPLACEDTEXT, font to replacedfont, and so on...
|
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Thu Aug 17, 2017 4:26 pm Post subject: |
|
|
Is the change to be reliably consistent in its pattern?
For example, no matter what is held in {$variable}, the desired result is literally:
replaced{$variable}
giving replacedfont, replacedtext, replacedfoo, replacedbar.
Or were your use of TEXT and REPLACEDTEXT just semantic placeholders?
That is, actual examples may be to change from FOO to BAR, or from BAZ to RUM.
If so, then we may be able to pass in arrays for the arguments. Smarty's replace modifier uses PHP's str_replace() function.
That will be something to test. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Thu Aug 17, 2017 4:42 pm Post subject: |
|
|
This seems to work:
Code: | {$LANG.title_my_notes|replace:['Notes','My']:['Comments','Your']} |
where $LANG.title_my_notes is My Notes, but the result is Your Comments.
The brackets are PHP's alternate syntax to indicate an array. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Aug 17, 2017 7:17 pm Post subject: |
|
|
Yes, since replace internally uses (mb_)str_replace, you could use arrays to make multiple replacements at once. |
|
Back to top |
|
qgoodlike Smarty n00b
Joined: 17 Aug 2017 Posts: 3
|
Posted: Sun Aug 20, 2017 6:52 am Post subject: |
|
|
bsmither wrote: | This seems to work:
Code: | {$LANG.title_my_notes|replace:['Notes','My']:['Comments','Your']} |
where $LANG.title_my_notes is My Notes, but the result is Your Comments.
The brackets are PHP's alternate syntax to indicate an array. |
Thanks! It really works. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|