wirePopulateStringTags() function
Given a string ($str) and values ($vars), replace “{tags}” in the string with the values
- The
$varsshould be an associative array of[ 'tag' => 'value' ]. - The
$varsmay also be an object, in which case values will be pulled as properties of the object.
By default, tags are specified in the format: {first_name} where first_name is the name of the
variable to pull from $vars, { is the opening tag character, and } is the closing tag char.
The tag parser can also handle subfields and OR tags, if $vars is an object that supports that.
For instance {products.title} is a subfield, and {first_name|title|name} is an OR tag.
Please note this method is and thus not intended to be called directly.
Example
$vars = [ 'foo' => 'FOO!', 'bar' => 'BAR!' ];
$str = 'This is a test: {foo}, and this is another test: {bar}';
echo wirePopulateStringTags($str, $vars);
// outputs: This is a test: FOO!, and this is another test: BAR! Internal usage
// basic internal usage
$string = wirePopulateStringTags (string $str, $vars);
// internal usage with all arguments
$string = wirePopulateStringTags (string $str, $vars, array $options = array);Arguments
| Name | Type(s) | Description |
|---|---|---|
$str | string | The string to operate on (where the {tags} might be found) |
$vars | WireData object array | Object or associative array to pull replacement values from. |
$options (optional) | array | Array of optional changes to default behavior, including:
|
Return value
stringString with tags populated.
Functions methods and properties
API reference based on ProcessWire core version 3.0.252