Twig title print 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 index()
    {
        $data = [
            'title' => 'Welcome to CodeIgniter with Twig',
            'message' => 'This is a sample page using Twig as the template engine.',
            "items" => array(
                array("name" => "Item 1", "description" => "This is item 1"),
                array("name" => "Item 2", "description" => "This is item 2"),
                array("name" => "Item 3", "description" => "This is item 3"),
            ),
            "heading1" => "Harry-ONE",
            "heading2" => "Harry-TWO",
            "heading3" => "Harry-THREE",
            "heading4" => "Harry-FOUR",
            "heading5" => "Harry-FIVE",
            "heading6" => "Harry-SIX",
            "paragraph1" => "This is Harry",
            "paragraph2" => "This is new paragraph",
            "paragraph3" => "Lorem ipsum dolor sit amet consectetur",
            "strong_text" => "This is strong",
            "paragraph4" => "adipisicing elit. Harum suscipit a sed magni excepturi nisi id, consequuntur at molestiae incidunt. Sunt harum,",
            "emphasized_text" => "This is Emphasized",
            "paragraph5" => "architecto vitae est soluta optio perspiciatis. Repudiandae, eveniet?",
            "paragraph6" => "Lorem ipsum, dolor sit amet consectetur adipisicing elit.",
            "paragraph7" => "At minima impedit, deleniti vero necessitatibus voluptatibus officiis dolorum voluptatum placeat harum fugiat repellendus vel consequatur porro possimus. Facilis pariatur consequatur accusantium!",
        ];

        $this->twig->render('welcome_message.twig', $data);
        $this->twig->render("Headings_Paragraphs.twig", $data);
    }

    public function textLetter()
    {
        $data = array(
            "title" => "Welcome Twig",
            "title2" => "Hello Welcome to Twig, we are from textLetter function",
        );
        $this->twig->render("uppercase.twig", $data);
    }
}





VIEW FILE
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="vieport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    <body>
        <p>{{ title2 }}</p>
    </body>
</html>



Comments