1

In my database I have escapde each string with addslashes http://php.net/manual/fr/function.addslashes.php

Now I want to "unescape" my data with stripslashes to display them in a twig view http://php.net/manual/fr/function.stripslashes.php

I'm not using a framework. Only a PHP MVC architecture. Twig was installed with composer and works fine.

Here is how I tried to implement my new filter in TWIG :

require './vendor/autoload.php';

/**
 * TWIG
 */
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('vue');
$twig = new Twig_Environment($loader, array('debug' => true));
$twig->addExtension(new Twig_Extension_Debug());
$filter = new Twig_SimpleFilter('strips', function ($string) {
    return stripslashes($string);
});
$twig->addFilter($filter);

How I try to use :

{{ realisation.getName | strips }}

And the answer :

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The filter "strips" does not exist in "allReal.twig"
Leinox
  • 279
  • 1
  • 3
  • 10

0 Answers0