Welcome Guest, Not a member yet? Register   Sign In
Load CSS/JS dynamically in header.php depending on current view
#3

[eluser]Unknown[/eluser]
Interesting. I'll explore that approach further as I get more time.

For the meantime, I've accomplished what I originally set out to do by creating a property named $view in my controllers that contains the name of the view. The only downside to this is that each of my controllers has to contain this property but that's a minor issue.

Within my header I can now output my CSS as follows:

Code:
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url();?>content/css/app/<?php echo $this->view; ?>/index.css" />

Within my footer I can likewise output the appropriate script file as follows:

Code:
< script src="<?php echo base_url();?>content/js/app/<?php echo $this->view; ?>/index.js">< /script>

Of course this approach only works under the assumption that each view has a single JS and CSS file, but I could easily define an array property that includes several files and output those in a loop.


Messages In This Thread
Load CSS/JS dynamically in header.php depending on current view - by El Forum - 03-10-2013, 10:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB