Default layout cakePHP

1.3k Views Asked by At

I have a simple question , I am trying to use ONE default layout with header and footer to automatically show in other .ctp files when I make them, but for some reason I cannot do it and also I was thinking of using one javascript file to show in all the other pages as well , can someone give me with example on how to make the header and footer from one default file show up on all the other files.

Thank you for your help

1

There are 1 best solutions below

1
mart On

Here an example for your default.ctp

default.ctp

<html>
<head>
    <!-- 
    //here your javascript yourscript.js 
    //It will be present in all your views.
    //the file has to be present in /app/webroot/js 
    -->
    echo $this->Html->script('yourscript');

</head>
<body>

    <!--
    //header
    //the file header.ctp has to be present in /View/Elements
    -->
    echo $this->element('header');

    <!--
    //here the content, for example from /View/Posts/edit.ctp
    -->
    echo $this->fetch('content');

    <!--
    //footer
    //the file footer.ctp has to be present in /View/Elements
    -->
    echo $this->element('footer');

</body>
</html>

$this->fetch('content') ist the "magic" part of CakePHP. Here will be fetched your view.