Welcome Guest, Not a member yet? Register   Sign In
Template library : add_region()
#1

[eluser]Marcela[/eluser]
Hello, I am new to CodeIgniter, a friend of mine recommended me this framework, he gave me a zip with an installation base that included the Template library(Collin Williams).

After reading the documentation and play around with the library, I have only one question, how do you add a region to the template and that this be printed?

I have set three fixed regions in the configuration file of the Template library:
-header
-content
-footer

I have this files into my application folder:

controllers/test.php
Code:
<?php
class Test extends controller {

  function Test(){
    parent:Controller();
  }

  function index() {
    $this->load->library('template');

    $this->template->write('header', 'the header');
    $this->template->write('content', 'the content');
    $this->template->write('footer', 'the footer');

    $this->template->add_region('extra');
    $this->template->write('extra', 'the extra content'); // never displayed

    $this->template->add_css('styles/file.css');
    $this->template->add_css('scripts/utils.js');

    $this->template->render();
  }
}
?>

views/template.php

Code:
<html>
<head>
<title>Prueba de template</title>
<?php echo $_styles ?>
<?php echo $_scripts ?>
</head>
<body>
<div id="header">
&lt;?php echo $header ?&gt;
</div>
<div id="content">
&lt;?php echo $content ?&gt;
</div>
<div id="footer">
&lt;?php echo $footer ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;

The problem as you can see is, how the hell I do to make the new region is displayed in the output??.

I mean how add:

Code:
&lt;?php echo $extra ?&gt;

To template, how??

Maybe passed loading a view(error... I try this yet), $this->load->vars, abracadabra, shazaamm!!, a pact with the devil.


thank you in advance.
#2

[eluser]ralf57[/eluser]
A quick look at the library shows that there's a "add_region" method that does just what you need.
The next time have a look at the code before posting help requests, you can save a lot of time ;-)
#3

[eluser]Marcela[/eluser]
[quote author="ralf57" date="1272974462"]A quick look at the library shows that there's a "add_region" method that does just what you need.
The next time have a look at the code before posting help requests, you can save a lot of time ;-)[/quote]

You dont read the complete post.

I know the method add_region() exist, if you read the code I used it, my question is, How I do to get the NEW region displayed?, beacuse as I say I have only three regions (fixed) on config(template) and in template file.

I mean how I tell the template to echo the region.
#4

[eluser]ralf57[/eluser]
I am afraid that you cannot write to region whithout the matching variable in the template ($extra in you case).
The "add_region" is useful when you need to load different templates, but it doesn't seem to be your case
#5

[eluser]Marcela[/eluser]
Well, thank you anyway, Template library rock's, but this function ( add_region() ) seems more useful than it really is.




Theme © iAndrew 2016 - Forum software by © MyBB