开发者

how to convert an HTML template into Cake PHP template

开发者 https://www.devze.com 2023-03-21 19:28 出处:网络
I\'m a beginner in cake php. i have needed to convert my HTML template into 开发者_开发技巧Cake PHP template. any idea?It is very easy.

I'm a beginner in cake php. i have needed to convert my HTML template into 开发者_开发技巧Cake PHP template. any idea?


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号