Welcome Guest, Not a member yet? Register   Sign In
Wich is the best way of doing a template view in CodeIgniter?
#1

[eluser]Sinclair[/eluser]
Hi,

I'am with some trouble working with the views in CodeIgniter...

I have done a "main template view" that is the HTML that is the same in every page, and then I have "sub-views" that show on the "main template view".

The main problem that I have right now with this is the JavaScript, the <head> TAG is on the "main template view" and must to put all JavaScript code in there... the problem is that some "sub-views" generate JavaScript... and that is the problem...

My question:

How do you deal with Templates and JavaScript?

Where can I read about Template techniques to use in CodeIgniter?


Best Regards
#2

[eluser]Colin Williams[/eluser]
My very basic javascript helper (actually part of a generic helper I typically use). Modify it at will.

Code:
function add_js($path = FALSE)
{
  static $js;
  if ($path)
  {
    $js .= '< script type="text/javascript" src="'. $path .'"></ script >';
  }
  else {
    return $js;
  }
}

function get_js()
{
  return add_js();
}

In your template view

Code:
<head>
<?php print get_js() ?>
</head>
#3

[eluser]Fabdrol[/eluser]
I use a _interface() method in my controllers, like this:

Code:
function _interface($subview, $data = false) {
    if($data && is_array($data)) {
        $pass = $data;
        // to pass non-standard variables to my template
    }

    // pass the standard variabls to my template
    $pass['subview'] = $subview;
    $pass['my_other_standard_vars'] = '';
    $pass['...'] = '';
    // et cetera

    $this->load->view('global/interface', $pass);
}

... And in the interface.php view:

Code:
<head>
    <title>My fantastic design</title>
</head>

<body>
    <?php $this->load->view($subview); ?>
</body>




Theme © iAndrew 2016 - Forum software by © MyBB