1

I am writing a webpage with CI.I use the latest version. I need to learn how to imply CSS and Javascript files. I use nivoslider , jquery and many css files. I use application directory as

+application
  +views
    +pages
     -home.php
    +templates
     -header.php
     -footer.php
+system
+user_guide. 

Can you explain how to enable js and Css files. I made a research but my mind is blown away with the versions of codeigniter. this is my header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN
     ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Kırmızı Eğitim Merkezi</title>
        <meta name="description" content="Empire - XHTML Template" />
    <!-- CSS -->
    <link href='./fonts/sansation.css' rel="stylesheet" type="text/css" />
    <!-- Get any font from here easily: http://www.google.com/webfonts -->
    <link href="./css/style.css" rel="stylesheet" type="text/css" />
    <link href="./fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet" 
          type="text/css" />
    <link href="./css/nivo-slider.css" rel="stylesheet" type="text/css" />

    <!-- UPDATE BROWSER WARNING IF IE 7 OR LOWER -->
    <!--[if lt IE 8]><link href="css/stop_ie.css" rel="stylesheet" 
         type="text/css" /><![endif]--><!-- JAVASCRIPTS -->
    <script type="text/javascript" src="./js/jquery.min.js">
    </script><script type="text/javascript" 
         src="./js/jquery-ui-1.8.17.custom.min.js">
    </script><script type="text/javascript" 
         src="./fancybox/jquery.fancybox-1.3.4.pack.js">
    </script><script type="text/javascript" src="./js/jquery.nivo.slider.js">
    </script><script type="text/javascript" src="./js/jquery.bgslider.js">
    </script><script type="text/javascript" src="./js/preloader.js">
    </script><script type="text/javascript" src="./js/farbtastic.js">
    </script><script type="text/javascript" src="./js/basic.js">

    </script>

Can you advice me a way to use them ?

1 Answer 1

3

First, you need to place JS and CSS files somewhere like:

+ assets
   + js
   + css

Then you need to call them:

<link href='<?php echo base_url(); ?>assets/css/cssfile.css' rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery.min.js">
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer is obviously right and this isn't a criticism but when I use base_url() I like to put the url inside it as I find it a little neater to read :) <?php echo base_url('assets/css/cssfile.css'); ?> just putting that out there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.