CodeIgniter Forums
Template Library Version 1.4.1 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Template Library Version 1.4.1 (/showthread.php?tid=12840)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24


Template Library Version 1.4.1 - El Forum - 07-28-2010

[eluser]jmanpa[/eluser]
I figured it out and will share the results here:

1) short tags, as used in Template code examples, were not working with my ci and Apache config (not allowing short tags). I had to set $config['rewrite_short_tags'] = TRUE; in the config.php file.

2) I had ordered these incorrectly and footer was defined in both with the last one understandably overriding the second (the second had an empty footer):

$template[‘default’][‘regions’][‘footer’] = array(
‘content’ => array(‘c 2010 mycompany’)
);

$template['default']['regions'] = ...


Template Library Version 1.4.1 - El Forum - 08-19-2010

[eluser]Billy Khan[/eluser]
Having a wierd problem with this library,

My code:
Code:
$header_data['user'] = $this->ion_auth->get_user();
$scripts = "";
$this->load->model("videos_model");
$data['videos'] = $this->videos_model->get_videos();        
$this->template->write('page_title','');
$this->template->write('scripts', $scripts);
$this->template->write_view('header', 'main.header.php', $header_data);
$this->template->write_view('content', 'video_manager.home.php',$data);
$this->template->write_view('footer', 'main.footer.php');
$this->template->render();

When i try and loop round $videos within video_manager.home.php, it stops parsing and doesnt output main.header.php ,main.footer.php. As soon as i replace my loop with a simple echo "hello"; it works. Why would looping round my dataset stop all templates from parsing?

Using mamp / php 5.3.2


Template Library Version 1.4.1 - El Forum - 08-19-2010

[eluser]Billy Khan[/eluser]
Scratch that, my bad. get_videos() was booged.


Template Library Version 1.4.1 - El Forum - 08-19-2010

[eluser]cryogenix[/eluser]
[quote author="Dave Hunt" date="1278641623"]Great library, but I have one question.

You have an example in the documentation where you only ever use one header and footer for a template, so you configured:

Code:
$template['default']['regions']['header'] = array('content' => array('<h1>CI Rocks!</h1>'));
$template['default']['regions']['footer'] = array('content' => array('<p id="copyright">© Our Company Inc.</p>'));

Is there a way to do this, except to grab a view file instead of just putting text in the config file itself?[/quote]

I'll do it like this:
Code:
&lt;?php
  class Default_Page_Controller extends Controller
  {
    public function __construct()
    {
      parent::__construct();

      $this->template->write_view("header", "default_header");
      $this->template->write_view("footer", "default_footer");
    }
  }
?&gt;

I will then place this in my application's libraries folder and let it be autoloaded using this magic function which I added at the bottom of my application's "config.php" (I forgot where I got this but I just copied it at some thread here in the CI forums):

Code:
/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
  if(strpos($class, 'CI_') !== 0)
  {
    @include_once( APPPATH . 'libraries/'. $class . EXT );
  }
}

This way, I now have an always existing library. I can just let it be extended by the controller of whatever page that needs the default header and default footer.

Say for example the index page:

Code:
&lt;?php if(!defined("BASEPATH")) exit("No direct script access allowed");
  class Welcome extends Default_Page_Controller
  {
    public function __construct()
    {
      parent::__construct();
    }

    public function index()
    {
      $this->template->write_view("content", "content_welcome");
      $this->template->render();
    }
  }
?&gt;

So there you have it. This approach can also be applied for other uses such as securing pages that require authentication by simply extending something like a Protected_Page_Controller wherein that controller contains some session checking logic.


Template Library Version 1.4.1 - El Forum - 09-27-2010

[eluser]ITT-Nico[/eluser]
Hey guys, i was just wondering if it is possible to read the content of a region?

Just because of some idea im having...

Thx


Template Library Version 1.4.1 - El Forum - 09-27-2010

[eluser]WanWizard[/eluser]
If you want to do it correctly, add this
Code:
function get_region($name)
{
   if (isset($this->regions[$name]['content']))
   {
      return $this->regions[$name]['content'];
   }
   else
   {
      show_error('The "'. $name .'" region is undefined.');
   }
}

But as all class properties are public, you can also access them directly
Code:
echo $this->template->regions[$name]['content'];



Template Library Version 1.4.1 - El Forum - 09-27-2010

[eluser]ITT-Nico[/eluser]
Okey THx!


Template Library Version 1.4.1 - El Forum - 09-29-2010

[eluser]cryogenix[/eluser]
has any1 tried using this btw for CI2?

i seem to be having some problems trying to make it work.

i've copied the package in their respective folders, configured the template config, all pretty much like how i used to do it in CI 1.7.2. but all i get is an undefined variable $template when i try to call $this->template

well of course I know that it's not meant for use with CI2 yet but I would just like to know if someone already managed to make it work and how?


Template Library Version 1.4.1 - El Forum - 09-29-2010

[eluser]victorche[/eluser]
@cryogenix, I am using it with CI 2.0 with no problems at all. Check your installation again and ask if you need help.


Template Library Version 1.4.1 - El Forum - 09-29-2010

[eluser]cryogenix[/eluser]
nvm... i found out it i wasn't using modular extensions hmvc properly *forgot to change extends Controller to extends MX_Controller