Welcome Guest, Not a member yet? Register   Sign In
Template Library Version 1.4.1

[eluser]pnd_ku[/eluser]
Hello!

Have little suggestion. I had to import google map api JS file, but there is no way to do it with standart add_js function. So i`v wrote little extension to this function, could be included in next release. Second parameter of add_js now could be also 'absolute' to include absolute JS file path.

Code:
// --------------------------------------------------------------------
  
   /**
    * Dynamically include javascript in the template
    *
    * NOTE: This function does NOT check for existence of .js file
    *
    * @access  public
    * @param   string   script to import or embed
    * @param   string  'import' to load external file or 'embed' to add as-is or 'absolute' to add absolute js file
    * @param   boolean  TRUE to use 'defer' attribute, FALSE to exclude it
    * @return  TRUE on success, FALSE otherwise
    */
  
   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;
            
    case 'absolute':
            $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;
   }

[eluser]bremerg[/eluser]
I'm using Template Library 1.4.1 with CodeIgniter 1.7.2. I'm moved the 3 required files to the appropriate locations with the application/config, application/libraries and application/views folders. However, when I use this line in my Controller class...

Code:
$this->load->library('template');

...I receive the following error...

Code:
Unable to load the requested class: template

I read through this entire thread and I've tried a number of the suggestions offered including Colin Williams' "My hunch is that, if anything, it has to do with the recent class name change from 'Template' to 'CI_Template'. It seems to work thus far, but it’s not 100% proven. Try renaming the class and see if that doesn't help." in this post: http://ellislab.com/forums/viewthread/95687/P40/#494510. Nothing seems to work.

Has anyone figured out a solution for this issue? Or do I need to use an older version of CodeIgniter?

Thanks!

[eluser]Tominator[/eluser]
Hi!

It's looking that this class has history Smile So I think you can solve my problem:
http://ellislab.com/forums/viewthread/152634/

It's my Template Parser. I was using it for long time in PHP, but I start using CI about month ago and I rewrite for CI - and I have some problems Big Grin

Thanks,
Tom.

[eluser]bremerg[/eluser]
While I appreciate your suggestion that I try out your new template system, Tominator, I am more interested in figuring out how to make this one work.

If anyone has constructive suggestions on what I need to do to make this Template Library work, I would love to hear them. Thanks!

[eluser]Tominator[/eluser]
If you use my T. Parser, you just have to:
1, Copy parser.php to your libraries
2, Use: $this->load->library('parser');

And are ready ... continue by docs ... it's super simple!

[eluser]oualid[/eluser]
Hi.

I have downloaded and installed the template library version 1.4.1.
When I call the template from the controller I get the following error:

Your template.php file does not appear to contain a valid configuration
array.

I am using CI version 1.7.2.

Any Idea?

Regards.

/Oualid

[eluser]paulc010[/eluser]
Colin,

I've been playing with this for a couple of days now, and feel I should provide some feedback:

Awesome work!

I have to say that even I have not managed to break this, and I've been trying out some really, really dodgy things that I never expected to be able to get to work, at least not easily!

I have a nice playground now with Modular Extensions providing "widgets" executed from within view files written (or parsed) into Template regions (I'm using load->view() from within the widgets in the modules own view files) so am really just using these as dynamically generated "partials".

I'm also happily using dwoo thanks to the superb work done by Phil Sturgeon ( http://philsturgeon.co.uk/code/codeigniter-dwoo ). Works right out of the box and creates huge possibilities!! Recommended.

As I said I've been mixing and matching different ways of including data into the final rendered output, and from reading this thread I can see that many issues would probably be solved using this approach rather than trying to use the template library for everything. As an example of what I've been playing with I have a "home" controller:
Code:
function index()
    {
        // Add any required css and javascript to the render queue
        $this->template->add_css('css/news.css');

        $data = array();

                // Do stuff to gather all the data together in here

        $this->template->parse_view('content','home',$data);
        $this->template->render();
    }

With the view file home.php containing:

Code:
{$my_variable['data']}
{modules::run('news/_embed')}

The "news" module is a simple blog controller which normally displays all the posts (actually paginated in the real controller) via the index function. When using Template I can have the blog posts within the "content" Template region as normal, but I can also add an additional function in the module controller for use when I just want to embed the data as a "partial" in another page (as in the case of the view example above):

Code:
function index()
    {
        $data = array();
        $this->_build_all($data);

        // Go ahead and render it within the template...
        $this->template->write_view('content', 'news/news_index', $data);
        $this->template->render();
    }

    function _embed()
    {
        $data = array();
        $this->_build_all($data);

        // Go ahead and render it as a partial...
        $this->load->view('news/news_index', $data);
    }

    function _build_all(&$data)
    {
        // Fill $data with the content we want to display
    }

Another topic that seems to have cropped up in the thread a few times is management of css and javascript in the header. It's great to be able to add js and css when required within normal controllers and module controllers to ensure that they will always be included, and one copy only! When it comes to the final output of the page however, it would be nice to be able to generate a single "minified" version built from the included files (obviously version checked and cached too for efficiency) as has been suggested already in this thread.

As a (temporary?) hack I've actually been experimenting with a further level of abstraction using CI's hook functionality. Using this method I can create a "template" for the page header with placeholders for the css and javascript and then insert the content after Template et al have done their work, with additional processing as required.

I'll write that up in a separate post if anyone is interested - this one is getting way too long as it is!

Once again - many thanks for your work on this!

Paul

[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.

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.

[eluser]Unknown[/eluser]
This template library is great, i very like it and now i'm using it. Thanks author Big Grin

[eluser]Unknown[/eluser]
Hi there,

Can I use HMVC ( http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/ ) plugin with this template system?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB