2011-10-27 3 views
0

두 가지 질문이 있습니다. 하나는 나뭇 가지 코드 구문의 태그 이름이고 다른 하나는이 태그를 수정하는 방법입니다.나뭇 가지 이스케이프 태그

태그 : 두 예에서 {{ 'Some text' }} 또는

{{ "Some text" }} 그것은 "일부 텍스트"를 표시합니다,하지만 난 표시하기 전에 내 기능 (translate())를 사용하고 싶습니다. 이 태그의 이름조차 모르기 때문에 어디에서 코드를 검색해야하는지 모르겠습니다.

내가, 표시하기 전에 구문 분석 된 텍스트를 번역 예컨대 원하는 : {{ 'Some text' }} -><?php echo translate('Some text'); ?>

답변

0

자신의 Twig extenstion을 확인합니다. 튜토리얼은 here입니다. 가장 우아한 방법입니다.

확장 :

class Translate_Twig_Extension extends Twig_Extension 
{  
    public function getFunctions() 
    { 
     return array(
      'translate' => \Twig_Function_Method($this, 'translate', array('is_safe' => array('html'))) 
     ); 
    } 

    public function translate($text) 
    { 
     // do the magic, return translated text 
    } 
} 

템플릿 :

{{ translate('some text') }}