Welcome Guest, Not a member yet? Register   Sign In
How to create templates
#1

Hi 
I am new to codeigniter and i want to create a template for my codeigniter website so that that template appears in in pages in both admin and front side of the website. I read tutorial for simple header and footer view files but that is not enough, i want full examples. If there are any prepared template demo available online then tell me here.

Thanks in avance.
Reply
#2

@mitsol,

Maybe this will be useful to you... https://www.google.com/search?q=codeigni...e&ie=UTF-8
Reply
#3

See blog Avenir:https://avenir.ro/en/
or buy book "Practical CodeIgniter 3"- Lonnie Ezell.
Reply
#4

Which version of CodeIgniter are you using?

If it's the latest CI4 - templating is very easy. Take a look at this - https://codeigniter4.github.io/userguide...youts.html

Step 1 - create your template file - Views/app.php

PHP Code:
<!doctype html>
<
html>
<
head>
   <title>My Layout</title>
</
head>
<
body>
   <?= $this->renderSection('content'?>
</body>
</html> 

Step 2 - create any page e.g. home page Views/homepage.php
PHP Code:
<?= $this->extend('app'?> //This is the name of layout file above without ".php" 

<?= $this->section('content'?>
    <h1>Hello World! Welcome to my website.</h1>
<?= $this->endSection() ?>

Step 3 - In your controller
PHP Code:
public function index()
{
 
   echo view('homepage');


Depending upon your are requirements - you can create different types of layouts e.g. publicLayout.php or adminLayout.php

You can also include partials too - check out all options here - https://codeigniter4.github.io/userguide/outgoing
Reply
#5

Maybe you'll like BladeOne: https://github.com/EFTEC/BladeOne
Reply
#6

The best way is to load views within your views.

Within views/content.php:

<? $this->view('header', array('title'=>'The page title', 'keywords'=>'some keywords', 'etc'=>'...')); ?>
<div id="content">My content here</div>
<? $this->view('footer'); ?>
So in your controller you would do this:

$this->load->view('content', $data);
$data could contain 'title' or 'keywords' and that would be implemented as such in your controller:

$data['title'] = 'title';
$data['keywords' = 'keywords';
And this in your 'content' view:

<? $this->view('header', array('title'=>$title, 'keywords'=>$keywords)); ?>
<div id="content">My content here</div>
<? $this->view('footer'); ?>
This question is worded differently, but nearly identical to this one in substance: CodeIgniter or PHP Equivalent of Rails Partials and Templates
No SEO spam, per forum policy
Reply
#7

I've created a Layout Library that manages the templates.
You can find it here: https://github.com/vmoulin78/codeigniter-layout-library
Reply




Theme © iAndrew 2016 - Forum software by © MyBB