J
J
jugger32020-06-19 16:25:44
PHP
jugger3, 2020-06-19 16:25:44

How to convert php to twig correctly?

if (isset($_POST['textcontent'])){
    $text=$_POST['contetnt'];
}
 $arr = array(
        'Имя: ' =>$name,
        'Номер телефон: ' =>$phone,
        'Комментарий:' =>$callback_comment,

        
    );

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmitriy, 2020-06-19
@dmitriylanets

$this->twig->render('template.twig',$arr)

H
hesy, 2020-06-19
@hesy

$ composer require twig/twig

require 'vendor/autoload.php';

$loader = new \Twig\Loader\FilesystemLoader('/app/views');
$twig = new \Twig\Environment($loader, [
  'cache' => '/storage/cache/twig',
  'auto_reload' => true,
  'debug' => true,
]);

echo $twig->render('index.html', ['name' => 'Вася']);

index.html
<p>Привет, {{ name }}</p>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question