1

I'm trying to use str-replace() PHP String Functions for content of custom tag, class or id, in addition i want to understand Is it possible to use that or similar Functions in twig template?

To resolve this issue I wrote something like below code to my ThemeName.theme:

function ThemeName_preprocess_node(&$variables) {
$variables['<div class="info">']= str_replace(
array('A','B','C','D','E','F'),
array('1','2','3','4','5','6'),
$variables['<div class="info">']
);
}

I Try out Many different ways but I can't get any result.I would be happy to hear what the problem is and guide me to To resolve this problem.

Mojtaba Reyhani
  • 447
  • 1
  • 6
  • 19

1 Answers1

1

There is discussion on this subject here:

str_replace in Twig

Accepted answer is pointing to replace filter:

http://twig.sensiolabs.org/doc/filters/replace.html

So something like:

{{some_string|replace({'A':'1','B':'2','C':'3','D':'4','E':'5','F':'6'})}}

should work.

Community
  • 1
  • 1
MilanG
  • 6,994
  • 2
  • 35
  • 64