Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Please help! Replace

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
qgoodlike
Smarty n00b


Joined: 17 Aug 2017
Posts: 3

PostPosted: Thu Aug 17, 2017 1:12 pm    Post subject: Please help! Replace Reply with quote

How to make multiple values "replace", for example:
{$variable|replace:'TEXT':'REPLACEDTEXT'}
TEXT to REPLACEDTEXT, font to replacedfont, and so on...
Idea Question Question
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Thu Aug 17, 2017 4:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Thu Aug 17, 2017 4:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Aug 17, 2017 7:17 pm    Post subject: Reply with quote

Yes, since replace internally uses (mb_)str_replace, you could use arrays to make multiple replacements at once.
Back to top
View user's profile Send private message
qgoodlike
Smarty n00b


Joined: 17 Aug 2017
Posts: 3

PostPosted: Sun Aug 20, 2017 6:52 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP