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 - 10-11-2010

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

Anyone have problems with template write_view() function when using it in a controlloer loaded via Modules::run()?

A clearer picture, let's say we have the following structure in modules folder.

Module1
Module1/controllers
Module1/views

Module2
Module2/controllers
Module2/views

If we do a modules::run('module2/controller/function') from a controller in module1 folder, template->write_view() calls from module2 will use module1/views folder instead of the correct module2/views folder.

Template's write_view() function is a shortcut for $this->load->view() and $this-template->write(). The problem I think lies with the template->write_view() code but I've no idea on how to fix it (yet).

Currently I am using this very ugly workaround from inside module2, which defeats the whole purpose of using the Template class..

$this->template->write_view($region, '../modules/module2/views/someviewfile');

This ensures that any other module calling this module knows where to find the right view files. The alternative workaround is even more hideous..

$string = $this->load->view('someviewfile', '', true);
$this->template->write($region, $string);


Hope that someone here have a more elegant solution for this problem.


Template Library Version 1.4.1 - El Forum - 10-20-2010

[eluser]Flightkid[/eluser]
Get this problem: http://img197.imageshack.us/img197/4351/1285748584571.png
Any help is appreciated, thanks in advance.


Template Library Version 1.4.1 - El Forum - 10-21-2010

[eluser]WanWizard[/eluser]
Your using $this->template, but the template library isn't loaded anywhere?


Template Library Version 1.4.1 - El Forum - 10-21-2010

[eluser]Flightkid[/eluser]
Ok wow dumb mistake thanks for the help. Fixed it by adding template to the autoload in the config.


Template Library Version 1.4.1 - El Forum - 10-26-2010

[eluser]momsenmeister[/eluser]
I only started using the Template Library a day ago, so I'm a total newbie.

I don't really understand how it is possible to nest templates in templates / views in views?
It's no problem to nest views in template regions, but what if that view itself should behave like a template, and contain regions for example?

In this example (which is not working, obviously) I want do demonstrate how I would like to write to the views regions first, and then nest this view in the template's region.
Code:
// This is, what I don't understand
// How can I use the Template Library for nested views?
$this->template->write_view('view1_contentregion', 'titletext');

// This is possible already
$this->template->write_view('template_contentregion', 'view1');

// Render
$this->template->render();

Any possibility to do something like this?
How do you solve such a problem?


Template Library Version 1.4.1 - El Forum - 10-26-2010

[eluser]Phil Sturgeon[/eluser]
You can do this with my Template library, but I call them Partials.


Template Library Version 1.4.1 - El Forum - 10-26-2010

[eluser]Vheissu[/eluser]
[quote author="Phil Sturgeon" date="1288104893"]You can do this with my Template library, but I call them Partials.[/quote]

Wow Phil, are my eyes deceiving me or did you finally create some documentation for your template library?


Template Library Version 1.4.1 - El Forum - 10-26-2010

[eluser]cryogenix[/eluser]
hmmmm... do not get yourself confused with "template" and "views" when you're using this library. templates are, as the name implies, a template. like this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
  &lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;?=$title;?&gt;&lt;/title&gt;
    &lt;?=$_styles;?&gt;&lt;?=$_scripts;?&gt;

    &lt;style type="text/css"&gt;
      body {
       background-color: #fff;
       margin: 40px;
       font-family: Lucida Grande, Verdana, Sans-serif;
       font-size: 14px;
       color: #4F5155;
      }

      a {
       color: #003399;
       background-color: transparent;
       font-weight: normal;
      }

      h1 {
       color: #444;
       background-color: transparent;
       border-bottom: 1px solid #D0D0D0;
       font-size: 16px;
       font-weight: bold;
       margin: 24px 0 2px 0;
       padding: 5px 0 6px 0;
      }

      code {
       font-family: Monaco, Verdana, Sans-serif;
       font-size: 12px;
       background-color: #f9f9f9;
       border: 1px solid #D0D0D0;
       color: #002166;
       display: block;
       margin: 14px 0 14px 0;
       padding: 12px 10px 12px 10px;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
&lt;?=$header;?&gt;
&lt;?=$content;?&gt;
&lt;?=$footer;?&gt;
  &lt;/body&gt;
&lt;/html&gt;

while a view can be anything you can put in the $header, $content, & $footer in my given example. like this for the $content (filename: welcome_message.php):

Code:
<p>[color=green]&lt;?=$loadatexthere;?&gt;[/color]</p>
<p>[color=red]&lt;?=$wellloadaviewhere;?&gt;[/color]</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
<p><br />Page rendered in {elapsed_time} seconds</p>

now now, you want to nest views you say? say for example you want another view loaded into your content view?

well well, in my way of using this "awesome" library, i'd do it like this:

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

    public function index()
    {
      $content_view_data = array
      (
        "loadatexthere"     => "lorem ipsum dolor sit amet";
        "wellloadaviewhere" => $this->load->view("my_nested_view", true);
      );

      $this->template->write("title", "myCI");
      $this->template->write("header", "<h1>Welcome to CodeIgniter!</h1>");
      $this->template->write_view("content", "welcome_message", $content_view_data);
      $this->template->write("footer", "<pre>footer here</pre>");
      $this->template->render();
    }
  }
?&gt;

notice that for the main template, i only write to the main regions i have specified. and as for sub views, the traditional $this->load->view can be used. i hope you got what i'm talking about. i'm a little bit in a hurry as my work shift is nearing its end Tongue might edit this post at home later Tongue

ciao!


Template Library Version 1.4.1 - El Forum - 10-26-2010

[eluser]Phil Sturgeon[/eluser]
[quote author="Vheissu" date="1288105310"][quote author="Phil Sturgeon" date="1288104893"]You can do this with my Template library, but I call them Partials.[/quote]

Wow Phil, are my eyes deceiving me or did you finally create some documentation for your template library?[/quote]

The doctor said I have a bit of a fever and it should go away soon. Don't expect to be seeing too much more! :-p


Template Library Version 1.4.1 - El Forum - 10-26-2010

[eluser]momsenmeister[/eluser]
Thx a lot guys!
Phil's library is probably exactly what I'm looking for, I'll give it a try...
I hope not to get a fever, too - having to read through all that bulky documentation ;-)
Thx, greets from Germany!