Part of the EllisLab Network
   
 
Templating
Posted: 21 November 2008 02:25 PM   [ Ignore ]  
Summer Student
Total Posts:  6
Joined  08-18-2008

I’m just curious…something I have not been able to determine reading the docs hitherto is how you templatize an applicaiton so each page follows similar navigation.

How do you handled situations where a login form might displayed on each page until an individual is logged in at which a “My toolbox” might replace it?

Do you use a HTML static template and “inject” the dyanmic body contents into the template using str_replace?

This would apply to both the body content and possible navigation in the case of login FORM’s?

If you could point to an article on best practices in this regard I would appreciate it.

Cheers,
CB

Profile
 
 
Posted: 21 November 2008 03:07 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  126
Joined  04-03-2008

Usually, this question gets answered with this Template Library.

There are other types of template systems out there too.

Conceptually, to do it without a library works something like this.

Controller:

// - do a bunch of stuff
$data['some_info''my query results, or whatever';

// load a view, but have it return a STRING, 
// rather than writing output directly to the browser.
// we do that by passing TRUE as the third parameter
$some_output['main_content'$this->load->view('some_output'$dataTRUE);

// you can also have other output variables...
$some_output['section_title''My Section Title';
$some_output['breadcrumbs'$this->load->view('breadcrumbs'$dataTRUE);

// Then load whichever template you would like to display
if($my_site)
{
    $this
->load->view('templates/my_site'$some_output);
}
else
{
    $this
->load->view('templates/some_other_template'$some_output);

View -> templates/my_site:

<html>
<
head>
<
title><?php if(isset($section_title)) echo $section_title?></title>
</
head>
<
body>
<
div id="breadcrumbs">
  
<?php if(isset($breadcrumbs)) echo $breadcrumbs?>
</div>
<
div id="section_content">
  
<?php if(isset($content_main)) echo $content_main?>
</div>
</
body>
</
html
Profile
 
 
Posted: 21 November 2008 04:23 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  6
Joined  08-18-2008

OK Thank you…I figured it would look something like this but incase CI had some unique way of doing things I wasn’t sure.

Cheers,
Alex

Profile
 
 
Posted: 21 November 2008 04:27 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  126
Joined  04-03-2008

You’re welcome.

As is the case with much of CI, you can do it many different ways - it’s just a matter of what you need it to do for your particular situation.

Good luck,
Matt

Profile
 
 
Posted: 22 August 2009 09:53 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  109
Joined  08-12-2009

fesweb can you or anyone else, explain, a little bit further, this part:

// Then load whichever template you would like to display
if($my_site)
{
    $this
->load->view('templates/my_site'$some_output);
}
else
{
    $this
->load->view('templates/some_other_template'$some_output);


What is the $my_site function in this context, where does he/she come from?

Thanks a lot in advance,
Márcio

Profile
 
 
Posted: 22 August 2009 02:56 PM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  126
Joined  04-03-2008

The $my_site var is just an example of how you might handle a situation where a logged-in user sees one version of a page and a non-logged-in user might see another.

// this would solve the same problem (if it were a problem YOU needed to solve):
if($this->session->userdata('logged_in') == TRUE)
{
    $this
->load->view('templates/private_site'$some_output);
}
else
{
    $this
->load->view('templates/public_site'$some_output);
}
// OR forget the conditional altogether:
$this->load->view('templates/my_site'$some_output); 

It all depends on what you need to do.

Profile
 
 
Posted: 22 August 2009 09:32 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  109
Joined  08-12-2009

Thanks Matt. Indeed, I will need that part to… thanks for clarifying.

Normally the homepages have not similar layouts as the secondary pages.
Could a solution like this one, be a solution for thoses cases, where we need a homepage slidely different from the other pages?


Regards,
Márcio

Profile