Welcome Guest, Not a member yet? Register   Sign In
Accessing classes
#11

[eluser]garrettheel[/eluser]
The template library just allows for smarty-like php variables and statements in the views, does it not? I wasn't aware that the template library allowed for a way to include a global header and footer as default on all pages?
#12

[eluser]dpgtfc[/eluser]
[quote author="garrettheel" date="1228628131"]The template library just allows for smarty-like php variables and statements in the views, does it not? I wasn't aware that the template library allowed for a way to include a global header and footer as default on all pages?[/quote]

Maybe I am misunderstanding. When you say "header" and "footer" You mean the old school:

include "header.inc";

right?

If you have a template, why do you need a header and footer?

You do this in the controller:

Code:
function index()
{
   $sub_view_array = array();
   $template_vars = array();
  
   $data['main_content']= $this->parser->parse('sub_view',$sub_view_array,true);
   $this->parser->parse('main_template',$template_vars);
}

With a template system you don't need a header and a footer.
#13

[eluser]garrettheel[/eluser]
Maybe that is what I'm looking for..

If it's not too much trouble, could you give me a basic example of the index function with the header and footer included? (assuming they're both simply views)
#14

[eluser]dpgtfc[/eluser]
[quote author="garrettheel" date="1228628558"]Maybe that is what I'm looking for..

If it's not too much trouble, could you give me a basic example of the index function with the header and footer included? (assuming they're both simply views)[/quote]

With a template the header and footer don't need to be in seperate views. You would have one single php file like so:

Code:
<html>
   <head>
   </head>
   <body>
        <div id="topnav">{topnav}</div>
        <div id="wrapper">
           <div id="left-menu">{leftmenu}</div>
           <div id="content">
          
            {content}

            </div>
        </div>
   &lt;/body&gt;
&lt;/html&gt;

I mean you could, but there would be no benefit from it, as you can make any part of the single template entirely dynamic based on the controller.
#15

[eluser]garrettheel[/eluser]
So I get the templating system deal, but how are the variables $content and such passed to the view? Don't I need to explicitly state this somewhere?
#16

[eluser]garrettheel[/eluser]
Shameless bump..
#17

[eluser]Pascal Kriete[/eluser]
Quote:So basically what I’m trying to make is a page handler that is called at the end of a function when I want to display a page instead of $this->load->view(‘blah’);

Lots of ways to do this. You can nest views, so you could create a template view:
Code:
&lt;html&gt;
&lt;?php $this->load->view('general/header'); ?&gt;

&lt;?php $this->load->view($content); ?&gt;

&lt;?php $this->load->view('general/footer'); ?&gt;
&lt;/html&gt;

And then all you would need to do is define a content variable that references another view:
Code:
$data['title'] = 'My great Title';
$data['animal'] = 'Pelican';

$data['content'] = 'earth/fauna';
$this->load->view('general/template', $data);

The data variables are automagically available to all nested views.

You could take it a step further and create a library that does that logic for you, So it might have a function like this:
Code:
function render($content, $data)
{
    $data['content'] = $content;
    $this->CI->load->view('general/template', $data);
}

// Used as above, but instead of data['content']
// you pass the name of the view
$this->libraryname->render('earth/fauna', $data);

Hope I understood the question correctly Wink .




Theme © iAndrew 2016 - Forum software by © MyBB