0
votes

I wish to have a codeigniter application with 3 templates.

  1. a template for displaying a login view, or an error view.

  2. a template with header body navigation

  3. a template with header body sidebar footer

now I can build the codeigniter application, but I can't find a simple template system to accomplish this task. There are many recommendations for libraries available, but they lack implementation details.

Suggestions and guidance would be appreciated.

3

3 Answers

1
votes

You can user CodeIgniter Template. http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html Download here the library and also you have a full documentation.

With this library, you can use more than one template, and you can manage it easy and separate in groups.

0
votes

It's quite simple once you get your head around it.

You need to create a view file for each of the things you've listed above, so you'll want something like this (folder/file wise):

views/page-login.php
views/page-error.php
views/header.php
views/footer.php

Then from your controller you will load one of the page views. Within the page view you can then load the elements you require, so header and footer with the page specific code between them.

So for example your login page could be:

<?php $this->load->view('header'); ?>

    <h1>Login</h1>
    <p>Please login to my website.</p>

<?php $this->load->view('footer'); ?>
0
votes

This is fairly simple.

A quick example:

In your controller you can put

//a test variable
$data["foo"] = 'bar';
$data["page"] = 'a_page'; // this will make sure it loads the views/pages/a_page.php in your template
$this->load->view('templates/login',$data);

And in your views/template/login.php you can put:

<!-- your login template html  -->
<html>
    ...
    <!-- include the view you want inside your login template -->
    <?php $this->load->view('pages/'.$page);?><!-- As you can see it loads /views/pages/a_page.php -->
    <?php echo $foo;?> //This will echo Bar
</html>

or:

<?php $this->load->view('template/login_header');?>
<?php $this->load->view('pages/'.$page);?>
<?php $this->load->view('template/login_footer');?>

views/pages/a_page.php will also know $foo.

This loads another view (views/pages/a_page.php) in your template.

This way you can create all the templates you want, and include your view in those templates.

TIP: Handling headers & footers this way get's unmanageable pretty quickly. And it's still better to use template libraries. Try Phil sturgeon's library