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

[eluser]nsbingham[/eluser]
Nevermind the previous post. I had a mis-spelling in the module name I was loading.

[eluser]snaKeSz[/eluser]
Hi, there i just checked out your template engine. i get stuck at one point:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends CI_Controller {
    
    function __construct()
    {
        parent::__construct();
    }
    
   function index()
   {
      $pagename = "Test-Page";
  
      $this->template->write('head', '<link rel="stylesheet" type="text/css" href="templates/default/css/cms.css" />');
      $this->template->write('head', '<link rel="stylesheet" type="text/css" href="templates/default/css/style.css" />');
      $this->template->write('title', 'Title'.$pagename);
      $this->template->write_view('content', 'news/show', $this->news->show());
      $this->template->write_view('sidebar', 'news/latest');
      
      $this->template->render();
   }
  
}

it says: "
Fatal error: Call to a member function show() on a non-object in C:\Server\xampp\htdocs\CodeIgniter\application\controllers\page.php on line 17"

i got a controller called news with a method called show. Whats wrong? could you help me please? Smile

[eluser]permanentbraindamage[/eluser]
$this refers to the current controller, not some other controller. Therefore, $this->news would need to be a property (or model or library etc) of the current controller.

In your case, I speculate thta you most likely meant calling a show() method from a news model in $this controller. You will need to load the news model, or rework your controllers or read up on the CI and PHP documentation.

[eluser]Unknown[/eluser]
so i'm trying to get this setup with the latest version of CI and i cannot get it to bind the fields in the sample template. The title still shows
Code:
<?= title ?>
even though I have properly bound the field.

anyone know if there are issues with the latest version of CI and Template Library 1.4.1?
:-S

[eluser]cryogenix[/eluser]
there must be something wrong with your template's config. would you mind posting them? or your short_open_tag in php.ini might be off. but really, please do use <?php echo instead to ensure maximum compatibility.

[eluser]otherjohn[/eluser]
Hi,
I have somewhat posted this question elsewhere, but now I believe it might have something to do with the templating engine and HMVC.

In my Default template, I have
Code:
<nav id="subMenu">
    <ul>
        &lt;?php if (!$this->acl->has_permission('edit_content')): ?&gt;
        <li><a href="/admin/content">Content</a></li>
        &lt;?php endif; ?&gt;
    </ul>
</nav>

which throws the following error
Code:
ErrorException [ Fatal Error ]: Call to a member function select() on a non-object
APPPATH/models/acl_model.php [ 82 ]
77     }
78    
79    
80     public function get_user_roles($user_id)
81     {
82         $this->db->select('role_id');
83         $this->db->where('user_id',$user_id);
84         $this->db->order_by('addDate','asc');
85         $query = $this->db->get('user_roles');
86         return $query->result();    
87     }

If I was to put that line of code in a view, no error is thrown.
I am not sure why it is giving this error? Any ideas/

[eluser]emorling[/eluser]
Thanks for making this availabale! Is there a Wiki Parser you would reccomend, that I can use with the Template engine?

[eluser]Andreas Karlsson[/eluser]
Just wrote a hook that someone might be interested in, it makes you able to use a default view in a region.
Make sure you load the hook file after template has loaded. eg, post_controller_constructor.

config/config.php
Code:
$config['enable_hooks'] = TRUE;

config/hooks.php:
Code:
$hook['post_controller_constructor'] = array(
    'class' => 'Your_hook_class',
    'function' => 'hook_function',
    'filename' => 'your_hook_class.php',
    'filepath' => 'hooks'
);

config/template.php:
Code:
$template['default']['regions'] = array(
    'title',
    'header',
    'footer' => array(
        'view' => 'partials/footer'
    )
);

hooks/your_hook_class.php:
Code:
class Your_hook_class {
    
    function hook_function()
    {
        require(APPPATH . 'config/template.php');
        
        $ci =& get_instance();
        
        $template = $template[$template['active_template']];
        
        foreach ($template['regions'] as $key => $value)
        {
            if(is_array($value))
            {
                if(array_key_exists('view', $value))
                {
                    $ci->template->write_view($key, $value['view']);
                }
            }
        }
        
    }
}

Hope it helps. If someone knows a better way, or has some questions. Feel free Smile

[eluser]Uplift[/eluser]
is it possible to add a bit of code or a region to just 1 page?

[eluser]Carlton[/eluser]
I thought it was definitely worth sharing this...

I couldn't get the add_js features to work, I thought it may have been problems with CI 2.0 so did fresh install and it worked...eventually I found out that I had my add_js line above the template code which selects the template to use, looking back it was a silly mistake but hey.

Code:
public function page()
    {  
        // This line should go after I set the template
        $this->template->add_js('alert("Hello!");', 'embed');

        /* Bunch of code lines here */

        $this->template->set_template('public');

        $this->template->write_view('content', 'public/page', $data);
        $this->template->render();
    }




Theme © iAndrew 2016 - Forum software by © MyBB