Welcome Guest, Not a member yet? Register   Sign In
New to CI--Templating common data like external style sheet
#1

[eluser]cwscribner[/eluser]
Hi all.

I'm a few minutes into CI and my question (which may be irrelevant) is how can I template things with CI? So instead of putting <link rel....> on every view, how can I make it more automated?
#2

[eluser]Mirge[/eluser]
You could create header & footer views.

views/header.php:
Code:
<html>
<head>
<title>wassup</title>
<link rel="stylesheet" type="text/css" href="<?=site_url();?>assets/css/style.css" />
...
...

views/footer.php:
Code:
</body>
</html>

Naturally you'd create a folder "assets" in your application/ folder, and within that folder create your "css" folder, and put style.css there. You can use whatever folder you wanted, but it's common practice to use an assets/ folder.

And then in your individual view files:

Code:
<?php $this->load->view('header'); ?>

this is the body content for this particular view.
and some more content here.
and more here.

<?php $this->load->view('footer'); ?>

Hope that helps.
#3

[eluser]cwscribner[/eluser]
So I'm having some trouble with links in my code apparently? I'll post in blocks to make it work.

So here's what I've got...

header view
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;title&gt;vCTO</t[quote][/quote]itle>
    &lt;link href="&lt;?=site_url();?&gt;assets/css/style.css" media="screen" rel="stylesheet" type="text/css" /&gt;
    &lt;link href="&lt;?=site_url();?&gt;assets/css/dropdown/dropdown.linear.css" media="screen" rel="stylesheet" type="text/css" /&gt;
    &lt;link href="&lt;?=site_url();?&gt;assets/css/dropdown/themes/default/default.linear.css" media="screen" rel="stylesheet" type="text/css" /&gt;
&lt;/head&gt;
&lt;body&gt;

nav view
Code:
a bunch of links that the forums won't let me post for some reason...

footer view
Code:
&lt;/body&gt;
&lt;/html&gt;


welcome_message.php view
Code:
&lt;?php
        $this->load->controller('index');
?&gt;


welcome.php controller
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->view('header');
        $this->load->view('nav');
        $this->load->view('footer');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Right now, this doesn't display anything on the page. I followed your suggestion and created an assets directory that holds the css directory. I almost think that I may have overkilled it by using a controller on a page that doesn't need one but as I mentioned in my first post...I'm not very far into this. Any help would be greatly appreciated! :-)
#4

[eluser]cwscribner[/eluser]
Ok, I figured out what the problem was...it was the header view. I changed the &lt;?=siteurl();?&gt; to an absolute path and it fixed the problem. I also removed everything from welcome_message.php and modified welcome.php to include the welcome_message.php.
#5

[eluser]Mirge[/eluser]
Uhhhh.......

A view doesn't load a controller... a controller loads the view.

Before you dive too far in & get confused, take a bit to check out the user guide:

http://ellislab.com/codeigniter/user-guide/toc.html

Specifically:

Application Flow Chart
Model-View-Controller

Then I'd make sure to read ALL items under "General Topics", especially controllers, views, and models.
#6

[eluser]joakley77[/eluser]
Check out Carabiner. It allows you to group your assets (js/css) as well as minimizes them.

http://codeigniter.com/wiki/Carabiner/




Theme © iAndrew 2016 - Forum software by © MyBB