Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert an HTML template into Cake PHP template

Tags:

html

php

cakephp

I'm a beginner in cake php. i have needed to convert my HTML template into Cake PHP template. any idea?

like image 824
ram.info24 Avatar asked Jul 21 '11 13:07

ram.info24


2 Answers

It is very easy.

  1. Replace your template main file extension to .ctp
  2. index.html to index.ctp
  3. Look at the layout of you file (html code) and determine what section of that template you want to appear on all pages;
  4. Usually most templates are setup as follows:

    <html>
    <head>
        <title>My Site</title>
        // You will include your javascript and css files here
        <?php
            echo $this->Html->css(array('cake.generic','default'));
            echo $this->Html->script(array('myscript','jquery'));
        ?>
    </head>
    <body>
        <div id="container">
            <div id="header"></div>
            <div id="body">
                <div id="main_content" style="width:600px;float:left">
                       <?php 
                            //Code for this should be in your home.ctp
                            // in your pages folder. Usually I cut this content from
                            // my template and place the whole thing in that file
                            // everything else happens magically
                            echo $content_for_layout; 
                       ?>
                </div>
                <div id="side_content" style="width:300px;float:left">
                     <!-- You can have content here manually or create elements and include them here like the following -->
                     <?php $this->element("sidebar_content"); ?>
                </div>
            </div>
            <div id="footer">...</div>
        </div>
     </body>
    

  5. You should then upload all images to the /img folder in your /app/webroot folder

  6. Change your images path to reference /img folder.

  7. You must do the same with all your CSS and JS files. Place them in their corresponding folders in the /app/webroot location.

Good luck!

like image 101
AKKAweb Avatar answered Nov 14 '22 21:11

AKKAweb


Save your template in to APP/views/layouts/template.ctp.

Make sure it has at least two variables:

<title><?php echo $title_for_layout; ?></title>

and

<body>
    <?php echo $content_for_layout; ?>
</body>

Fire up your view, or controller and add $this->layout = 'template'; // view/method or $layout = 'template'; // controller;

Look at the Cake default.ctp for ideas.

like image 40
Ross Avatar answered Nov 14 '22 23:11

Ross