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.

Simple Question - Where am I suppose to put External CSS and Images

July 30, 2008 8:30am

Subscribe [5]
  • #1 / Jul 30, 2008 8:30am

    tfliam

    5 posts

    Hi, just wondering, where am I suppose to put all the External CSS, javascripts and Images ?

    Is it under ‘Views’ folder ? Because I can’t seem to access them directly.

  • #2 / Jul 30, 2008 8:44am

    Michael Wales's avatar

    Michael Wales

    2070 posts

    Anywhere you want - and use base_url() to setup a absolute URL to the file. There are various other ways but I find this the easiest.

    A quick search of the forums will reveal hundreds of topics concerning this.

  • #3 / Jul 30, 2008 11:48am

    I have done a screencast some time ago. Unfortunally the sound quality is really not good, but it will help you understand where to put your assets in a CodeIgniter application, look it following this link:

    http://www.codeigniterdirectory.com/component/option,com_mtree/task,viewlink/link_id,138/Itemid,10/

  • #4 / Aug 12, 2008 12:44am

    dameryworld

    7 posts

    An example always helps:
    For example you have a view file called site_view.php located in
    codeigniter/system/application/views/ folder.
    to use an external css file called site.css
    put the file in the same folder location
    codeigniter/system/application/views/
    then in your site_view.php file reference it by using the previous mentioned base_url() function.
    as seen below:
    <link rel=“stylesheet” type=“text/css” href=”<?php echo base_url(); ?>system/application/views/site.css” />

    *Note: At least it works for me. Hope this helps.

  • #5 / Aug 12, 2008 1:26am

    I would advice that you place your assets outside of the system folder (a “public” folder for example)

  • #6 / Aug 12, 2008 1:30am

    Colin Williams's avatar

    Colin Williams

    2601 posts

    CI doesn’t rewrite how Apache works. If you put a file at /web-root/images/image.gif, you can access that image with http://www.example.com/images/image.gif (or src=”/images/image.gif”, href=”/css/main.css”, etc)

  • #7 / Aug 12, 2008 4:52am

    m4rw3r's avatar

    m4rw3r

    647 posts

    Just remember that your .htaccess must not redirect those requests for the assets to CI.

    And as stated before in this thread, do not put the assets in the system or application directory (you may want to move system and application out of the webroot or rename them).
    Put them in a separate dir next to index.php, and use base_url() + ‘dirname/file.png’ to get the address.

  • #8 / Aug 12, 2008 8:30am

    dameryworld

    7 posts

    I am new to the whole MVC framework coding paradigm but I would think the css is an asset to the view and would need to be kept close to the file using it….maybe I should think of this as MVCA keeping Models Views Controllers and Assets in their own groups?
    *Note: The reason I wanted to put the css in the same folder as the view was in case I did move the view I wanted to keep associated css with it.

  • #9 / Aug 12, 2008 8:37am

    wiredesignz's avatar

    wiredesignz

    2882 posts

    Actually the View and the css are totally unrelated.

    Any properly coded view can be restyled.

    css is a (site) theme related component and should be located somewhere available to the browser.

  • #10 / Aug 12, 2008 8:46am

    dameryworld

    7 posts

    Ah, I get it. Like I said this is a new paradigm…I am still learning to break my ideas into MVC parts. Thanks for hanging with my slow paradigm shifting…

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

ExpressionEngine News!

#eecms, #events, #releases