CodeIgniter Forums
Placing Assets Q - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Placing Assets Q (/showthread.php?tid=18107)



Placing Assets Q - El Forum - 04-25-2009

[eluser]hasokeric[/eluser]
Does anyone have a tut/article to where to place the Assets (js/css/images) and how to link to them inside a page (a view) currently the method i am using is the xhtml tag base href however curious of a better method.

Thanks in advance.


Placing Assets Q - El Forum - 04-26-2009

[eluser]t'mo[/eluser]
The functions "site_url" in the URL helper and "link_tag" in the HTML helper come to mind.


Placing Assets Q - El Forum - 04-26-2009

[eluser]Thorpe Obazee[/eluser]
You can place them anywhere but personally I just create folders(css/images/js) on the root folder. then I use this helper:

Code:
<?php
/*
* @author        Thorpe Obazee
* @since        Version 1.1
* @license         BSD
*/

if ( ! function_exists('add_stylesheet'))
{
    function add_stylesheet($stylesheets = array())
    {
        if ( ! is_array($stylesheets))
        {
            $stylesheets = array($stylesheets);
        }

        foreach ($stylesheets as $key => $val)
        {
            html_stylesheet($key, $val);
        }
    }
}

if ( ! function_exists('html_stylesheet'))
{
    function html_stylesheet($src, $media)
    {
        echo "<link rel=\"stylesheet\" href=\"".base_url()."$src\" media = \"$media\" type=\"text/css\" />";
    }
}

To use:

Code:
<?php add_stylesheet(array('media/css/styles.css' => 'screen')); ?>