What to use instead of Twig_Loader_String

前端 未结 7 1973
醉梦人生
醉梦人生 2020-12-25 15:29

I see that the Twig_Loader_String class has been deprecated and will be removed in Twig 2.0. Also, the comments in the source indicate that it should \"NEVE

7条回答
  •  不思量自难忘°
    2020-12-25 16:00

    The best is: http://twig.sensiolabs.org/doc/2.x/recipes.html#loading-a-template-from-a-string

    As example used by me:

    public function parse($content, $maxLoops = 3, $context = array())
    {
        if (strlen($content) < 1) {
            return null;
        }
    
        for ($i = 0; $i < $maxLoops; $i++) {
            $template = $this->container->get('twig')->createTemplate($content);
            $result = $template->render( $context );
    
            if ($result == $content) {
                break;
            } else {
                $content = $result;
            }
        }
    
        return $content;
    }
    

提交回复
热议问题