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 - 01-21-2009

[eluser]Colin Williams[/eluser]
Quote:Are you planning support for pseudo-variables in future version’s(for teamwork with developer-designers)?.

I am not going to write a custom template parser, but you can plug in just about any template parser you want to, including Smarty and CI's native parser. See http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html#parsers


Template Library Version 1.4.1 - El Forum - 01-21-2009

[eluser]Colin Williams[/eluser]
Quote:Collin

Can you post here or in your site, examples of how use the add_region() feature.

Thanks

Well, it's only necessary if you want to create a region not defined in the config, or through the various levels of initialization functions (add_template, set_template, etc). It also enables easy plugin-like functionality. Say you developed a plugin system and added a user plugin. Within the user plugin, you could do something like

Code:
$ci =& get_instance();
$ci->template->add_region('user_tools');
$ci->template->write_view('user_tools', 'plugins/user_tools');

Then, all someone would have to do after activating this plugin is echo the $user_tools region where they want to in their main template.

Sometimes your template needs variables (settings, simple strings, etc) that don't make sense as regions--they aren't content buckets. In that case, I recommend using $this->load->vars() (won't work with parsers, unfortunately)


Template Library Version 1.4.1 - El Forum - 01-31-2009

[eluser]daweb[/eluser]
Hi,

great library!

I have to include an external js script.

I update the library/template.php code this way:

Code:
function add_js($script, $type = 'import', $defer = FALSE)
   {
      $success = TRUE;
      $js = NULL;
      
      $this->CI->load->helper('url');
      
      switch ($type)
      {
         case 'import':
            $filepath = base_url() . $script;
            $js = '[removed][removed]";
            break;
        
         case 'embed':
            $js = '[removed]";
            $js .= $script;
            $js .= '[removed]';
            break;
        // MY UPDATE
        // @ Aggiungo un case, nel caso in cui io volessi inserire un js esterno
        case 'import_external':
            $filepath = $script;
            $js = '[removed][removed]";
            break;
            
         default:
            $success = FALSE;
            break;
      }
      
      // Add to js array if it doesn't already exist
      if ($js != NULL && !in_array($js, $this->js))
      {
         $this->js[] = $js;
         $this->write('_scripts', $js);
      }
      
      return $success;
   }

Is this the right way to do that?!


Template Library Version 1.4.1 - El Forum - 01-31-2009

[eluser]Colin Williams[/eluser]
If it works, it's the right way! Smile There might be a more elegant solution I could bake in for the next release.


Template Library Version 1.4.1 - El Forum - 02-15-2009

[eluser]otherjohn[/eluser]
I am having an odd issue.
I have my default master template
Code:
$template['default']['template'] = 'master.php';
and on my controller for a page I have
Code:
if($comments)
{
//DO SOMETHING
    $this->template->write_view('main_content', 'phone/phone_details_no_comments_view', $data);
                $this->template->render();
}
else
{
//DO SOMETHING
$this->template->write_view('main_content', 'phone/phone_details_comments_view', $data);
                $this->template->render();

}


!!!!!EDIT!!!!!
Spoke to soon, didn't see the error on the bottom of the page in the view source.
fixed now.

Whats wierd is that only the phone_details_comments_view template loads up inside the master.php wrapper and not the other one. The phone_details_no_comments_view only loads up by itself.
Any idea what is happening?


Template Library Version 1.4.1 - El Forum - 02-16-2009

[eluser]Colin Williams[/eluser]
Quote:Whats wierd is that only the phone_details_comments_view template loads up inside the master.php wrapper and not the other one.

Um.. you have it in an if/else control statement. It would defy logic for both to happen.


Template Library Version 1.4.1 - El Forum - 02-23-2009

[eluser]JayTee[/eluser]
Seems as though a previous post of mine didn't quite make it..? Weird.

I have a question: (love the library, btw):

How do I deal with swapping between templates "on the fly":
This code causes a problem:
Code:
function index()
{
  $email = $this->input->post('email_address');
  $this->template->write('my_variable','value');
  $this->_send_email($email);
  $this->template->render();
}
function _send_email($address)
{
  $this->template->set_template('email');
  $msg = $this->template->render('',TRUE);
  //email functions
}
The email sends correctly, but I get an error when index() renders the page - it says that "my_variable" doesn't exist.

The reason I ask this is because I'm writing views to the template in the constructor of the controller (sidebar navigation based on the user's login). If I use set_template *after* the _send_email function, the template loses all the previous things I did to write to it.

Any suggestions? I'm just using the default CI load->view methods for the email function at the moment, but I figured I'd ask what the "template" way is Smile

Thanks


Template Library Version 1.4.1 - El Forum - 02-23-2009

[eluser]Colin Williams[/eluser]
For some scenarios, using views normally and not going through Template makes more sense, and that is what I would recommend. The error you are receiving means the 'my_variable' region doesn't exist. You either need to supply that region in config or use add_region() before trying to write to it.

Template is not designed to swap between templates in one request like that. Perhaps it should. But that is probably why the previous content is "wiped out."


Template Library Version 1.4.1 - El Forum - 02-23-2009

[eluser]Milos Dakic[/eluser]
[quote author="JayTee" date="1235465351"]
Code:
function index()
{
  $email = $this->input->post('email_address');
  $this->template->write('my_variable','value');
  $this->_send_email($email);
  $this->template->render();
}
function _send_email($address)
{
  $this->template->set_template('email');
  $msg = $this->template->render('',TRUE);
  //email functions
}
[/quote]

Just before you write the "my_variable" region, use the add_region function to add it first.


Template Library Version 1.4.1 - El Forum - 02-24-2009

[eluser]JayTee[/eluser]
[quote author="Milos Dakic" date="1235471727"]Just before you write the "my_variable" region, use the add_region function to add it first.[/quote]
The region actually exists in the controller's default template. It's when I did the set_template method to switch to my email view that it "lost" my previous data that I had written to the default.
[quote author="Colin Williams" date="1235468342"]Template is not designed to swap between templates in one request like that. Perhaps it should. But that is probably why the previous content is "wiped out."[/quote]It's alright :-)

What I really like about template is that I can use it for just about everything and then revert to the default CI
Code:
$this->load->view()
style whenever a need like this arises. It's quick, painless, and powerful.

Great work!

P.S. I discovered this library as a referral from Milos on another thread - it's pretty cool that you developed this and saved me a ton of work! http://ellislab.com/forums/viewthread/106592/