I had this same problem and here is how I took care of this.

I created 2 php files. One that had a CSS header so it would act as
CSS and the other, you guessed it, with a JS header.

I used the php include in those files to include any scripts that
would be used across the entire app.
// Below this line, EVERYTHING is include, unconditionally

include('site.generic.css');
include('elements/nav.css');

>From there I create a variable in the Views as so:
$this->set('css_var', array('form', 'post')) // Creates the variable
$css_var for use in the layout.

Then I manually call my css link in the layout:
<link href="/css/container.css.php<?php if(!empty($css)) echo '?';
        if(isset($css)){
                foreach ($css as $cssvalue){
                        echo $cssvalue.'=true&';
                }
        }" rel="stylesheet" type="text/css" />
That way if you're viewing a page that has form and post set for the
layout the php would output:
<link href="/css/container.css.php?form=true&post=true"
rel="stylesheet" type="text/css" />

Then back in the container.css.php file you'll just have to set up
some globals that link in the different CSS elements.
        if(@$_GET['form'] == 'true'){
                include('elements/form.css');
        }
        if(@$_GET['post'] == 'true'){
                include('elements/post.css');
        }

I use this technique to keep my css and js files as small as possible
for each view. It also makes editing and debugging easy because if I
notice that there is a problem with the form styles I have to open up
my elements/form.css file and scroll a few lines instead of hundreds.

Just keep in mind that a dynamic spreadsheet should not cache.

On Nov 17, 10:10 am, teknoid <[EMAIL PROTECTED]> wrote:
> > - Having the ability to add view-specific CSS or Javascript
>
> That's what $scripts_for_layout is for.
> You use it in conjunction, with the false param for CSS and
> 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 to manage CSS and Javascript inside my
> > app.
>
> > This is my goal:
> > - Having one (or many) CSS files common to all views
> > - Having one (or many) Javascript files common to all views
> > - Having the ability to add view-specific CSS or 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