2017-03-24 22 views
1

私はtwigテンプレートとの関係に問題があります。 codes.namely同じHTMLとしてphp twigテンプレートhtmlコード

final class index { 

public $request; 
private $loader; 
private $twig; 

/** 
* Constructor. 
* definition : class preloader with default 
* symfony component request class 
* twig template configuration 
* @param type dependency injection and function 
*/ 
public function __construct(){ 

    //get request info 
    $this->request=new request(); 
    $this->loader = new \Twig_Loader_Filesystem(root.'/src/declarations/twigTemplate'); 
    $this->twig = new \Twig_Environment($this->loader, array(
     //'cache' => root.'/src/declarations/twigTemplate/cache', 

    )); 
} 

/** 
* get declaration main function. 
* definition:index method is defined in a declaration 
* and it is called as https://ip/company/service/app/service/doc 
* @param type dependency injection and function 
* @return array 
*/ 
public function index(){ 

    //return 
    return $this->twig->render("index.twig",['var'=>'foo']); 

} 

}

私の小枝ファイルの出力は、HTMLのコードを実行されません。

index.twigファイル:

<strong>{{ var }}</strong> 

出力:

<strong>foo</strong> 

私はあなたがautoescapeタグおよび/または生を使用する必要があなたの答え

+0

'autoescaper'設定を変更しましたか? – DarkBee

+0

私はそれを試して、それは動作しません。 – JoBlox

+0

あなたはあなたがすでにそれを解決できると言った答えを投稿しましたが、おそらくあなたは小枝の文書を読んで、私が答えとして投稿したものを見つけましたか? –

答えて

0

ため、このproblem.alreadyおかげで解決することができますタグ

{% autoescape %} 
    {{ var|raw }} {# var won't be escaped #} 
{% endautoescape %} 

だからこれを言うことができます:

{% set example= "<h1>Test</h1>" %} 
{{ example|raw }} <-- This will output Test in H1 
{{ example }} <-- This will output <h1>Test</h1> 

私はあなたがすでにあなたの問題の答えを見つけたと知っています。しかし他の人がこの問題を抱えている場合、これは小枝でHTMLを出力する解決策です。お役に立てれば。

+0

OPの 'HTML'はOPの質問にあるように変数の中にないので、' raw'と 'autoescape'は何も解決しません。 – DarkBee

+0

ああそうです。ごめんなさい。 brainfartか何かを持っていて、それを小枝の構文として読んだ。変数はPHPにあります。おっとっと。 –

関連する問題