autoload stylesheet - 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: autoload stylesheet (/showthread.php?tid=4549) Pages:
1
2
|
autoload stylesheet - El Forum - 12-01-2007 [eluser]josh48202[/eluser] i created a separate stylesheet to keep the stuff organized better for the stuff i add in and i edited the autoload.php file n added Code: $autoload['stylesheet'] = array('application/views/stylesheet.css'); autoload stylesheet - El Forum - 12-02-2007 [eluser]BoltClock[/eluser] You can't autoload stylesheets as far as I know. I would create a directory under /application/views called /css, then save the stylesheet in there. Then I'd create a separate view file called header.php and add the <link /> pointing to the stylesheet and get all my view files to include('header.php') at the top the old school way. Don't worry, I'm new to CI too so there may be a better way around this. Hope that helped autoload stylesheet - El Forum - 12-02-2007 [eluser]josh48202[/eluser] i think what i added to the autoload.php worked but it doesnt always work on somefiles. some files i have to add the link to the stylesheet and the other times i dont. so i dont know autoload stylesheet - El Forum - 12-02-2007 [eluser]Michael Wales[/eluser] You can't autoload a stylesheet. Your best bet is to create a global view file named header and then load that from all of your normal view files. autoload stylesheet - El Forum - 12-02-2007 [eluser]josh48202[/eluser] alright well b4 i tried autoloading the stylesheet i was using this so il just stick with this instead of doing the header thing ur guys are taling about Code: <style type='text/css'> autoload stylesheet - El Forum - 12-02-2007 [eluser]Michael Wales[/eluser] That's basically what we're saying to, except rather than typing that into every file you can do something like this: _global/header.php Code: <html> whateverview.php Code: <?= $this->load->view('_global/header'); ?> There are quite a few advantageous to this - mainly, if you ever change stylesheets (or add more), you only have to change one file. autoload stylesheet - El Forum - 12-02-2007 [eluser]josh48202[/eluser] ooo gotcha ya yea thats easier to remember and type thank you for your help. autoload stylesheet - El Forum - 12-28-2007 [eluser]adamp1[/eluser] I have just released by Asset Linker library. This does everything you want, so give it a go. Link is in my sig autoload stylesheet - El Forum - 12-28-2007 [eluser]Nick Husher[/eluser] Additionally, the "$this->file()" approach prints the contents of the stylesheet into a <style></style> block, which isn't ideal. If you externally link your stylesheets (with a <link/> tag or otherwise) and your server is set up correctly (with Last-Modified or Expires headers), you can significantly reduce your bandwidth needs for a given page because the stylesheet need only be downloaded once and can be used across pages. My only additional suggestion is to set a base href and declare everything relative to that: Code: <html> This way your server's base path could be "www.example.com" while your CodeIgniter base path (defined in config.php) can be something different, such as "www.example.com/my_CI_app/test" while still allowing you to use the same header template in all your views. autoload stylesheet - El Forum - 12-28-2007 [eluser]eggshape[/eluser] One solution I've used is to create a CSS-autoload helper, autoload the helper using CI, and then call the helper function in each view to pull the correct CSS according to the viewfile name. |