CodeIgniter Forums
how to load the css from view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to load the css from view (/showthread.php?tid=57880)



how to load the css from view - El Forum - 04-22-2013

[eluser]sureshls[/eluser]
Hi,

I have my styles & script into view folder. The folder structure will be

../applications/views/admin_temp/default/assets/css/admin_style.css
../applications/views/admin_temp/temp1/assets/css/temp_style.css

now, i need to call/ apply the style (admin_style.css or temp_style.css) in my view files. How to do that?

Thanks








how to load the css from view - El Forum - 04-22-2013

[eluser]tauruss[/eluser]
Generally, css should be not in views folder, but outside of application folder.
For example, you can create a "css" folder in your main folder (where index.php is stored),
and then use function link_tag from HTML Helper in your view,
just like in example in manual

http://ellislab.com/codeigniter/user-guide/helpers/html_helper.html#link_tag


how to load the css from view - El Forum - 04-22-2013

[eluser]sureshls[/eluser]
Thanks Tauruss, but i have few templates in view folder also. Like template for admin login & template for user login. Even i have the css file outside the application folder. I have to call both css. How to do that?

Thanks


how to load the css from view - El Forum - 04-22-2013

[eluser]Aken[/eluser]
Load it with a <link> tag, like you would any CSS file...


how to load the css from view - El Forum - 04-22-2013

[eluser]jairoh_[/eluser]
<link rel="stylesheet" href="that path" /> Big Grin


how to load the css from view - El Forum - 04-23-2013

[eluser]tauruss[/eluser]
As I said before, you can use link_tag() function, or just simply <link> tag in your html document with template.
But why do you want load both of them ? Maybe I understood you wrong, but you said, that you have two css files, one for admin pages, second for users pages.
You shouldn't load css, if it is not necessary. You can avoid this by passing to the view variable with proper css file, for example:
pass to view variable $css, with filename of css (user.css / admin.css) depending which one should be used,
and then in view You use link_tag()

Code:
$link = array(
          'href' => 'css/' . $css ,
          'rel' => 'stylesheet',
          'type' => 'text/css',
          'media' => 'print'
);

echo link_tag($link);