Twig Paragraph and Headings 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);
}
}
VIEW FILE
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<body>
<h1>{{ heading1 }}</h1>
<h2>{{ heading2 }}</h2>
<h3>{{ heading3 }}</h3>
<h4>{{ heading4 }}</h4>
<h5>{{ heading5 }}</h5>
<h6>{{ heading6 }}</h6>
<p>{{ paragraph1 }}</p>
<p>{{ paragraph2 }}</p>
<p>{{ paragraph3 }} <strong>{{ strong_text }}</strong> {{ paragraph4 }} <em>{{ emphasized_text }}</em> {{ paragraph5 }}<p>
<hr>
<p>{{ paragraph6 }}<br>{{ paragraph7 }}</p>
</body>
</html>

Comments
Post a Comment