Most of the solutions provide are very ugly and messy as well.

What you really want is to add and remove css/js files as and when you
want and display them when you want too.

To do that you need this:

In the app_controller.php declare a var to hold all the js and scc
files like so:

var $css_files = array('core); // you can add default files to the
array
var $js_files = array('prototype.js'); // you can add default files to
the array

in the beforeRender set the data


function beforeRender(){
$this->set('js_files',$this->js_files);
$this->set('css_files',$this->css_files);
}

Now in any controller you can add css or js files to your page

Example:

A page that has a form

example_controller.php

function add(){
        $this->css_files[]  = 'form'; //it can be an array as well
        $this->css_files[]  =  array('form','signup','any_css_file'); //it
can be an array as well
        $this->js_files[]  =  'fake_script.js'; //it can be an array as well
}

Now in your layout you add  this

//You may can create an element if you like
//echo $this->element('page_files', array('page_files' => array( 'send
in the data to the element' )));

//OR

if(isset($css_files)){
        echo $html->css($css_files);  // you may need to put inside a foreach
depending on your version of CakePhp
}

if(isset($js_files)){
        if(is_array($js_files)){
                foreach($js_files as $js_file){
                        echo $javascript->link($js_file);
                }
        }
        else{
                echo $javascript->link($js_files);
        }
}

Hope it solves your problem

Will write a tutorial on how to do this soon.....

Marcus

W:<a href="http://www.marsilva.karoo.net/blog/";>Web Development
Programming Blog</a>



On Nov 17, 4:10 pm, teknoid <[EMAIL PROTECTED]> wrote:
> > - Having the ability to add view-specificCSSor Javascript
>
> That's what $scripts_for_layout is for.
> You use it in conjunction, with the false param forCSSand
> Javascript.
> So, for example, from your view:
>
> $html->css('my_css_file', 'stylesheet', array("media"=>"all" ),
> false);
> $javascript->link('my_js_file', false);
>
> will include both files in place of $scripts_for_layout, which should
> be in the <head> of your layout.
>
> On Nov 17, 9:28 am, i_Am_ToO_SeXy <[EMAIL PROTECTED]> wrote:
>
> > Hello.
>
> > CakePHP is driving me mad.
>
> > I can't figure out a smart way tomanageCSSand Javascript inside my
> >app.
>
> > This is my goal:
> > - Having one (or many)CSSfiles common to all views
> > - Having one (or many) Javascript files common to all views
> > - Having the ability to add view-specificCSSor Javascript
>
> > I tried almost 15 ways without success. I can't understand where's my
> > error(s)
>
> > Sry for bad english.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to