ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Confounded with CSS file!!!

November 25, 2009 5:25pm

Subscribe [3]
  • #1 / Nov 25, 2009 5:25pm

    puddles

    4 posts

    I’ve done a lot of reading of posts in this forum on how to locate your css file, and have tried each method.  For the life of me, I can’t seem to get it working though!

    Here is the location of my css file which I would like to call in a header view:

    xampp
    -> htdocs
      -> codeigniter
          -> system
              -> assets
                -> css
                    -> screen.css

    Here is my base url from my config.php:

    $config[‘base_url’]  = “http://localhost/codeigniter/”;

    Here is my controller code

    <?php
    
    class Welcome extends Controller {
    
        function Welcome()
        {
            parent::Controller();    
        }
        
        function index()
        {    
            
            $this->load->view('header');
            $this->load->view('welcome_message');
            $this->load->view('footer');
        }
    }


    Here is my header view:

    <html>
    
    <head>
    <title>Welcome to Hockeypool Headquarters</title>
    
    <style type="text/css">
    
        <?php echo link_tag('assets/css/screen.css'); ?>
    
    
    </style>
    </head>

    No matter what I seem to do, I’m not able to get the css to apply to the welcome_message.php page.

    When I look at the rendered page source, I see the following in the head section:

    <style type="text/css">
    
        <link  href="http://localhost/codeigniter/assets/css/screen.css" rel="stylesheet" type="text/css" />
    
    </style>

     

    Can anyone point out where I’ve gone wrong?

  • #2 / Nov 25, 2009 7:47pm

    John_Betong

    690 posts

     
     
    Try:

      // config.php
      $config[‘base_url’]  = “http://localhost/”;

      // header view
      <?php echo base_url(); ?>‘assets/css/screen.css’
     
      // if the above link is not valid then echo base_url() and adjust the path.

     
     
    edit: changed path
     

  • #3 / Nov 25, 2009 8:37pm

    puddles

    4 posts

    I tried your changes, but it did not work. 

    If the $config[‘base_url’] = “http://localhost/codeigniter/”; does it not correspond to this directory in my drive?

    D:/xampp/htdocs/codeigniter/

    If that is the case, and I have placed my css files in the following directory:

    D:/xampp/htdocs/codeigniter/assets/css/

    then shouldn’t the rendered link, as follows, be correct?

    <link href=“http://localhost/codeigniter/assets/css/screen.css” rel=“stylesheet” type=“text/css” />

    But it still the css files do not seem to take effect.  I feel like I’m missing something very simple.

  • #4 / Nov 25, 2009 8:42pm

    khagendra

    44 posts

    Your base_url is ok.
    Inside <head></head> tag use like this.

    <link href="<?=base_url()?>assets/css/screen.css" rel="stylesheet" type="text/css" />

    Your problem will be solved.

  • #5 / Nov 26, 2009 2:38am

    Aken

    2430 posts

    Actual file URLs are different than CodeIgniter Controller URLs.  Your CSS and related assets are still physically located in the system folder, according to your example.  Your code is fine, you’re just not including the full location.

    <?php echo link_tag('system/assets/css/screen.css'); ?>
  • #6 / Nov 26, 2009 9:49am

    puddles

    4 posts

    Thanks…..that works.

  • #7 / Nov 27, 2009 10:31am

    gh0st

    130 posts

    I don’t put my assets in the system folder.  I put it outside of CI altogether and keep it seperate.

    ie:
    /assets/css/
    /assets/js/
    /assets/images/
    ..etc
    /system/

    Then I make sure in the <head> of any document I put:

    <link rel="/assets/css/whatever.css" />
    <base href="<?=base_url();?>" />

    This seems to work fine.

  • #8 / Nov 27, 2009 3:56pm

    Aken

    2430 posts

    I don’t put my assets in the system folder.  I put it outside of CI altogether and keep it seperate.

    ie:
    /assets/css/
    /assets/js/
    /assets/images/
    ..etc
    /system/

    Then I make sure in the <head> of any document I put:

    <link rel="/assets/css/whatever.css" />
    <base href="<?=base_url();?>" />

    This seems to work fine.

    In most situations, with this file structure, you wouldn’t even need the base HREF defined.  But it doesn’t hurt.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases