Welcome Guest, Not a member yet? Register   Sign In
Templating System
#1

[eluser]PHP Creative[/eluser]
Hi there. I'm completely new to CodeIgniter. One thing I am struggling to understand is the templating system. Is it possible to have one 'index' file that includes the design (html + CSS) and then the content pages are included into it via the url eg urlhere.com/about/ would include the about page etc etc...

Before using CodeIgniter on most sites I would use index.php?content=home, about, contact etc.

Code:
<html>
<body>
<div id="footer">SITE HEADER</div>
<div id="contents">&lt;? include '$content.php'; ?&gt;</div>
<div id="footer">SITE FOOTER</div>
&lt;/body&gt;
&lt;/html&gt;

Is there a similar approach you can use in CodeIgniter?

Thanks a million
#2

[eluser]Jondolar[/eluser]
The "typical" way is to load a header, then your content, then a footer. However, you can do what you are asking as well.

If you are not familiar to MVC frameworks, you need to know that you will typically have a controller/function for your pages such as welcome/home, welcome/about, welcome/contact, etc. Each of these functions will load the header, load their content specific page and then load the footer.

The documentation on views is pretty good to explain this.
#3

[eluser]Colin Williams[/eluser]
You can either embed views or load them sequentially. It's up to you. See the Template library in my sig for an option that facilitates embedding views.
#4

[eluser]PHP Creative[/eluser]
Thanks a million for that library.

Is it possible to load separate views into the template using that library? I have tried loading the 'about' view into the template but it renders it before the template.

Code:
&lt;?php

class About extends Controller {
  
   function about()
   {
      parent::Controller();
   }
  
   function index()
   {
  
$this->load->view('about');

// Render the template
$this->template->render();
      
}
  
}


?&gt;
#5

[eluser]Colin Williams[/eluser]
That is expected behavior because of how you coded it. I would suggest fully reading the CI docs first then Template's docs.




Theme © iAndrew 2016 - Forum software by © MyBB