Twig "Date" tag with CodeIgniter in PHP

 <?php defined('BASEPATH') or exit('No direct script access allowed');


class Welcome extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->library("twig");
    }
    public function forLoop()
    {
        $data = array(
            "title" => "Welcome to Twig",
            "title2" => "Hello Welcome to Twig, we are from forLoop function",
            "title3" => "For Loop",
            "title4" => "Date",
            "title5" => "Current Date is : ",
            "items" => array(
                array("name"=>"Item 1 is Present", "description"=>"This is my Item 1"),
                array("name"=>"Item 2 is Present", "description"=>"This is my Item 2"),
            )
        );
        // $this->twig->render("for_loop.twig", $data);
        $this->twig->render("date.twig", $data);
    }
}




TWIG FILE IN VIEW
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title4 }}</title>
    <body>
        <h1>{{ title5 }}</h1>  {{ post.published_at|date("m/d/Y") }}
    </body>
</html>



Comments