Search code examples
phpcakephpstylesheet

Linking site-wide CSS file with CakePHP


I'm very new to PHP, and just customizing my homepage. This is the main layout I have for all of my pages:

<!DOCTYPE html>
<html>
    <head>
        <title><?php echo $title_for_layout ?></title>
        <?php echo $scripts_for_layout ?>
    </head>
    <body>
        <div id="header">

        </div>
        <div id="content">
            <?php echo $content_for_layout ?>
        </div>
        <div id="footer">

        </div>
    </body>
</html>

I want to have a global CSS file for all pages on my site called "style.css" which will be stored in app/webroot/css/style.css. I have tried doing this:

<!DOCTYPE html>
<html>
    <head>
        <title><?php echo $title_for_layout ?></title>
        <link href="<?php $html->css('style', 'stylesheet', array('media'=>'all' ), false); ?>" rel="stylesheet" type="text/css" />
        <?php echo $scripts_for_layout ?>
    </head>
    <body>
        <div id="header">

        </div>
        <div id="content">
            <?php echo $content_for_layout ?>
        </div>
        <div id="footer">

        </div>
    </body>
</html>

But it's not showing up in the output HTML. Any ideas?

Thanks!


Solution

  • you are definitely new to Cake :) here:

    <title><?php echo $title_for_layout ?></title>
      <?php 
        echo $this->Html->css('style');
        echo $scripts_for_layout;
      ?>
    

    That will output the full link element for you.