Replaces "{% <var> %}" in arrays or strings.

See all supported features & pipes in documentation of the core superReplace(...) function!


Syntax

superReplace($subject, $data = null, $rplNotFound = ''):string|array


Parameter

@param string|array $subject The original string or array(object) which is to be scanned & replaced. In case of a given (associative) array, the values and keys (!) are replaced.

@param array|null $data (optional, default NULL) Optional (multi-dimensional) array with  [(deep)key]="<value>" strings, which can be used to be replaced.

@param string|null (optional, default "") This string will be replaced per default, if a {% ... %} was not found in $data. If NULL, the original {%...%} is kept and not replaced.


Return

string|array|null Equivalent to $subject the same variable-type with the replaced content is returned.


Example

Writing in your twig source code:

{% set origStr = 'Hello {% firstname %}, ...' %}
{% set data = { "firstname": "Hubby" } %}

{{ hublify.superReplace( origStr, data) }}

renders to:

Hello Hubby, ...