Sol-Dev-993
Sol-Dev-993

Reputation: 63

Default layout cakePHP

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

Upvotes: 0

Views: 1343

Answers (1)

mart
mart

Reputation: 354

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.

Upvotes: 1

Related Questions