Welcome Guest, Not a member yet? Register   Sign In
passing static content to the template
#1

[eluser]martin79[/eluser]
Hi, I am new to CI and although no being a PHP expert I got (some) things working real quick.

I am trying to convert a static HTML website to CI. The basic template is the same through all pages, of course the content differs and there are some sidebars etc. on the subpages.

There is no database, all the content is static like I already said. Now I am not sure whats the best way to pass all the static content from the controlers to the template?

Would the right way be to create views (containing the actual content) for each content page and for all the sidebars and pass them to the template from the corresponding controller function?

Do I need to use an additional template engine (like http://code.google.com/p/ocular/) or can I achieve this by using the basic CI install?

Sorry, I know I am asking very basic, but Im just starting and still a bit lost.

Thanks, cheers
Martin
#2

[eluser]ehicks727[/eluser]
Don't know if this will help, but I just posted a pretty in-depth 'pattern' (sort of) for using MVC in CI.

http://ellislab.com/forums/viewthread/88904/#448932

For your particular situation, you'll want to add each static page as a route in the config/routes.php file. Then make a controller called 'static' or something like that. That way you don't have to create a controller for each static page.

Also, you'd be helping yourself by putting all your views in a separate folder for the static pages. I typically have a folder called views/content or views/staticpages or anything like that. This keeps your views folder somewhat organized.

Hope I helped you with at least some of your questions.
#3

[eluser]martin79[/eluser]
Hi, thanks for the reply.

What I wanted to say is that I have ONE master template that I use through my entire website. This master template has got "slots" that I need to fill up with static content.

I was searching whats the best way to do this.

Controler code:

Code:
$this->load->view ('master_template', array(
'content' => $this->load->view($view_name, null, true),
'sidebar_left' => $this->load->view($view_name, null, true),
'sidebar_right' => $this->load->view($view_name, null, true)
);

I would set up several functions in my controler(s) and could load my views into the main template.

Does this make sense? Dont know if the syntax is right...

Cheers
#4

[eluser]ehicks727[/eluser]
It would be easier to just load the content and sidebars in your template, not the controller.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
    &lt;title&gt;&lt;?=$titletag;?&gt;&lt;/title&gt;
    &lt;meta name="description" content="&lt;?=$metadescription;?&gt;" /&gt;
    &lt;meta name="keywords" content="&lt;?=$metakeywords;?&gt;" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="/css/common/style.css" /&gt;
&lt;/head&gt;
&lt;body&gt;
<div class="header">
    &lt;?= $this->load->view('header') ?&gt;
</div>
<div class="page-container">
    <div class="sidebar_left">
        &lt;?= $this->load->view($sidebar_left_view) ?&gt;
    </div>
    <div class="main">
        &lt;?= $this->load->view($content_view) ?&gt;
    </div>
    <div class="sidebar_right">
        &lt;?= $this->load->view($sidebar_right_view) ?&gt;
    </div>
</div>
<div class="footer">
    &lt;?= $this->load->view('footer') ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;

In your controller, set which file is the view for your sidebars and content like so

Code:
$this->data = array(
            'titletag' => 'This is the title tag',
            'metadescription' => 'This is your metadescription',
            'metakeywords'     => 'These are your metakeywords',
            'content_view'     => 'homepage',
            'content_view'     => 'homepage_sbl',
            'content_view'     => 'homepage_sbr',
            'content_data'    => ''
        );

Or something like that.
#5

[eluser]martin79[/eluser]
Oh, thanks..that looks much better!

Cheers
#6

[eluser]Colin Williams[/eluser]
Wrote the Template library just for you! Check the link in my signature.




Theme © iAndrew 2016 - Forum software by © MyBB