Auto Load CSS |
[eluser]Colin Williams[/eluser]
It's usually good to have some sort of "master" view or at least have a common header view of sorts. Then you can just put <link /> elements in there.
[eluser]Light North Media[/eluser]
Oh, thank you, would you mind outlining how that would work?
[eluser]bobbob[/eluser]
I may have mislead you You still need to link to it in your head of your pages. It is only convenient for portability: <link rel="stylesheet" type="text/css" href="<?php echo "$base.$css";?>"> Sorry.
[eluser]Light North Media[/eluser]
Oh, That makes sense now, thank you. Colin, how would I go about making a "master" header?
[eluser]darkhouse[/eluser]
A main header file is the way to go, and probably a footer file as well. Just take the top part of your code that never changes and throw it in a file called header.php (or includes/header.php which is what I do). Then in your view file just do <?php $this->load->view('includes/header'); ?> at the top. That way you only need to load one view from your controller as well. I don't know about you guys, but my projects usually have a lot of different javascript and css files. I like to separate css between the pages as a lot of the time they use a lot of different styles, so it doesn't make sense to load everything on every page. Same with javascript, and especially if it's a beefy script like tinymce. It makes sense to only load it on the pages that require it. Putting your <link>'s and [removed]'s right in your header doesn't cut it for me. I need the ability to have one header file, but different combinations of css and javascript files. I used to use a helper function and set a bunch of things in the array you send to the view, but I ended up writing a library for it instead as it made the most sense. Now I can put common things into a config file, and different things that I use on a per page basis in the controller.
[eluser]Iverson[/eluser]
[quote author="bobbob" date="1234173810"]in application/config/config.php is where you put the: $config[‘css’] = “mystyles.css”; I put it directly under $config['base_url'] Then just put the css file in the same directory as system: index.php mystyles.css system/Application/controllers user_guide The above being a sort of representation of the directory. Does that help?[/quote] You should have assets (javascripts, images, and css) in a separate folder to keep with the cleanliness and simplicity of CodeIgniter. The file structure would be similar to: -assets --css ---style.css --js ---jquery.js --images ---header.jpg Then you would use something like the Asset Manager to load your html.
[eluser]tonydewan[/eluser]
You might try using an asset management library. There are several in the Ignited Code section of the forum. I'm partial to the one I wrote, called Carabiner, but there are others. Carabiner allows you to load CSS and JavaScript assets similar to the what you tried to do. Here is an example: Code: $this->carabiner->css('externals/style.css'); Check out the Wiki for background info. |
Welcome Guest, Not a member yet? Register Sign In |