How create a template view, named default.php

What is a View?

“A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.”

The first part of this tutorial will educate complete beginners to create a template view, named default.php Interested? Let’s get started!

To start using our library, let’s create a template view, named default.php in application/views/templates, and place the following HTML/PHP inside:

<!DOCTYPE html>
<title><?php echo $title; ?></title>
<h1>Default template</h1>
<div class=”wrapper”>
<?php echo $body; ?>
In this template, we reference two variables, $title and $body.
Recall that in our template files, $body serves as a placeholder for an embedded view.
We shall now make another view to be embedded inside this template. Create a new file named content.php in application/views/ and place this simple HTML inside:
Hello world!
We are now ready to load the templated page view from within a controller.
Inside any controller method, place the following code to display the content view, within the default template.
$data = array(
‘title’ => ‘Title goes here’,
$this->template->load(‘default’, ‘content’, $data);

Note: the library has to be loaded in before you can call the load method. To save yourself loading the library every time a template view needs to be displayed,
autoload the class by adding it to the array of libraries in application/config/autoload.php.
If instead of a view file, you want a string to be embedded in the template, simply assign the string to the $data array using the key body, and pass null as the second parameter in the load call.
$data = array(

'title' => 'Title goes here',
'body' => 'The string to be embedded here!'
$this->template->load('default', null, $data);

Hi, i am a blogger,Digital Marketing Guy interested in posting some crazy posts on Blogging,Marketing & SEO,Marketing is very important in promoting content or products, Without that, you can't reach your goal. i like helping & motivating others by offering some free services.

We will be happy to hear your thoughts

Leave a reply

Reset Password