1

I created a module to extend Twig Extension for filter functions. However the usage of strtolower in custom module end up with no result. Below are the sampel code of my custom module.

  public static function removeSpaces($string) {
    $string = str_replace(' ', '-', $string);
    $string = strtolower($string);

    return $string;
  }

Filtering {{ title|removeSpaces }} in template end up with empty.

  • Can you debug what goes into the function and what comes out. Are those really strings? – 4k4 Jan 11 '17 at 14:10
  • Debug shows the strings {{ title }} is an array: – Hadafi Jan 11 '17 at 14:24
1

You have to render the array and then use the custom twig filter:

{{ title|render|removeSpaces }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.