How to add dynamic CSS and JS - need help |
Hi, I'm new to CodeIgniter.
I've been trying to use this code http://dondanu.com/add-dynamic-css-and-j...deigniter/ (another article i've found was 2013 http://jamshidhashimi.com/2013/04/12/dyn...ader-page/ ) It says: 1. Add new config item in your config file: PHP Code: $config['css_path'] = 'assets/css/'; 2. Create new helper file “helper/queuescript_helper.php” 3. In your controller file use below code, PHP Code: $data['css'] = array('bootstrap.css','custom.css'); 4. In your view, PHP Code: <?php queue_css($css);?> *** I ended up with this code (after rewriting it a bit): PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I added queuescript into autoload: PHP Code: $autoload['helper'] = array('html', 'url', 'queuescript'); There was an error: "Undefined variable: atts" and "Invalid argument supplied for foreach()" line 27, that is: PHP Code: foreach ( $atts as $key => $val ) But I added $atts = array() into line 21 PHP Code: queue_css($file, $media='all',$atts = array()) My base url is http://localhost/public_html path to css folder is: public_html/styles js folder is next to the codeigniter application folder in config I've got (I tried all variants of path): PHP Code: $config['css_path'] = 'styles/'; My browser doesn't see nor js nor css files. (I've restarted my wamp server). Please, help!
Hey, I'm really no expert, so appogogies if what I says is not helpful!
You say your base url is http://localhost/public_html and your css path is 'assets/css/'; Your css url function returns return base_url() . 'assets/css/' So that makes http://localhost/public_htmlassets/css/' That would have a slash missing between 'public_html' and 'assets'. Have you tried right clicking and looking at the source of the webpage to see what ends up being written in the html.
Also, I might misunderstanding but you say
path to css folder is: public_html/styles but your config says $config['css_path'] = 'assets/css/'; should it not be $config['css_path'] = 'public_html/styles';
No no. 'assets/css/' is that example path from the original article http://dondanu.com/add-dynamic-css-and-j...deigniter/
Mine is http://localhost/public_html/styles and my js folder is in the same folder the public_html is located. and this is in my config.php for css and js folders paths: PHP Code: $config['css_path'] = 'styles/';
Problem resolved!
I should have add echo into the piece of code for a header: PHP Code: <?php echo queue_css($css); ?> And I forgot to add one of my styles responsible for layout, that's why everything looked odd. |
Welcome Guest, Not a member yet? Register Sign In |