2012-03-09 15 views
18

मैं एक कस्टम टैग बनाया जो उस तरह काम करना चाहिए:Symfony2/टहनी: कैसे कस्टम टहनी टैग बताने के लिए नहीं से बचने के लिए उत्पादन

{{ thumbnail(image.fullPath,620) }} 

दुर्भाग्य से मुझे लगता है कि

{{ thumbnail(image.fullPath,620)|raw }} 
की तरह उपयोग करने के लिए है

क्या घुमावदार विस्तार में सीधे अनदेखा करने का कोई तरीका है?

मेरे विस्तार इस तरह थंबनेल कोड पंजीकृत करता है:

public function getFunctions() 
    { 
     return array(
      'thumbnail' => new \Twig_Function_Method($this, 'thumbnail'), 
     ); 
    } 

उत्तर

57

Twig_Function_Method::__construct() का तीसरा तर्क समारोह के लिए विकल्पों में से एक सरणी है।

public function getFunctions() 
{ 
    return array(
     'thumbnail' => new \Twig_Function_Method($this, 'thumbnail', array(
      'is_safe' => array('html') 
     )) 
    ); 
} 
+0

इसके लिए धन्यवाद। क्या यह प्रलेखन में निर्दिष्ट है? मुझे यह नहीं मिला, लेकिन शायद मैं काफी मुश्किल नहीं लग रहा था। –

+1

@StephenOrr क्रोज़िन के जवाब में लिंक देखें। – acme

+0

धन्यवाद, इससे मुझे $ मदद मिली) क्या आप इसके लिए मैन्युअल में लिंक जोड़ सकते हैं? जानना चाहते हैं कि 'html' विकल्प क्या हो सकते हैं – user1954544

3

टहनी इस तरह यह करता है: इन विकल्पों में से एक is_safe जो निर्दिष्ट करती है कि समारोह आउटपुट "सुरक्षित" HTML/जावास्क्रिप्ट कोड है

class Twig_Extension_Escaper extends Twig_Extension 
{ 
... 
    public function getFilters() 
    { 
     return array(
      new Twig_SimpleFilter('raw', 'twig_raw_filter', array('is_safe' => array('all'))), 
     ); 
    } 
... 
} 
... 

function twig_raw_filter($string) 
{ 
    return $string; 
} 
8

Crozin's answer सही है, बल्कि इसलिए अब \Twig_Function_Method हटा दिया गया है आप कर सकते हैं \Twig_SimpleFunction का उपयोग करें:

return [ 
    new \Twig_SimpleFunction('thumbnail', [$this, 'thumbnail'], [ 
     'is_safe' => ['html'] 
    ]), 
]; 
संबंधित मुद्दे