Conditionals in match_replace() #2

Closed
opened 2022-07-06 06:44:05 +00:00 by jamie · 7 comments
jamie commented 2022-07-06 06:44:05 +00:00 (Migrated from git.hazaar.io)

I would like to be able to specify conditionals in match_replace() strings. So, say I have a suffix I want to add to the string, but only if a value in the supplied data is TRUE.

Example usage:

Say we want to replace a string that has a name, followed but an active indicator.

$users= [
  [ 'name' => 'Joe Smith', 'active' => true ],
  [ 'name' => 'Jane Boots', 'active' => false ]
];

foreach($users as $user)
  echo match_replace('{{name}} {{?active:>(Active)}}', $users) . "\n";

This will output:

Joe Smith (Active)
Jane Boots

This will require two updates:

  • Output modifier > that will cause the defined plain text to be output directly.
  • The ? check modifier that will test the defined value and only output if it evaluates TRUE.
I would like to be able to specify conditionals in match_replace() strings. So, say I have a suffix I want to add to the string, but only if a value in the supplied data is `TRUE`. Example usage: Say we want to replace a string that has a name, followed but an active indicator. ```php $users= [ [ 'name' => 'Joe Smith', 'active' => true ], [ 'name' => 'Jane Boots', 'active' => false ] ]; foreach($users as $user) echo match_replace('{{name}} {{?active:>(Active)}}', $users) . "\n"; ``` This will output: ``` Joe Smith (Active) Jane Boots ``` This will require two updates: - [ ] Output modifier `>` that will cause the defined plain text to be output directly. - [ ] The `?` check modifier that will test the defined value and only output if it evaluates TRUE.
jamie commented 2022-07-06 06:44:06 +00:00 (Migrated from git.hazaar.io)

assigned to @jamie

assigned to @jamie
jamie commented 2022-07-06 06:44:22 +00:00 (Migrated from git.hazaar.io)

created branch 2-conditionals-in-match_replace to address this issue

created branch [`2-conditionals-in-match_replace`](/hazaar/hazaar-common/-/compare/master...2-conditionals-in-match_replace) to address this issue
jamie commented 2022-07-06 06:44:41 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !3

mentioned in merge request !3
jamie commented 2022-07-06 06:49:33 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2022-07-06 07:07:47 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2022-07-06 07:09:31 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2022-07-07 01:37:44 +00:00 (Migrated from git.hazaar.io)

mentioned in commit df0478099e

mentioned in commit df0478099ea14202f2b0ec6c534ef02fc92e2d10
jamie (Migrated from git.hazaar.io) closed this issue 2022-07-07 01:37:44 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/hazaar-common#2
No description provided.