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

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?

You could create header & footer views.

<link rel="stylesheet" type="text/css" href="<?=site_url();?>assets/css/style.css" />


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:

<?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.

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
<!DOCTYPE html>
&lt;html lang="en"&gt;
    &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;

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

footer view

welcome_message.php view

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

class Welcome extends CI_Controller {
    public function index()

/* 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! :-)

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.


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:



Application Flow Chart

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

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


Theme © iAndrew 2016 - Forum software by © MyBB