Using PHP include to separate site content

前端 未结 4 637
梦毁少年i
梦毁少年i 2020-12-03 16:17

I\'m looking for advice on the best practice for separating site content up into logical blocks. I want a header and footer that are constant throughout the site, so that if

4条回答
  •  没有蜡笔的小新
    2020-12-03 16:52

    In building off of Your Common Sense's answer, there's not a good reason to have 2 files for every page. You can easily combine your template (YCS called this .tpl.php) and your actual page into one file.

    First, start off with a class that you can expand as your template needs expand:

    Then, make your layout:

    
    
    
    
        <?php if(isset($TPL->PageTitle)) { echo $TPL->PageTitle; } ?>
        ContentHead)) { include $TPL->ContentHead; } ?>
    
    
        
    ContentBody)) { include $TPL->ContentBody; } ?>

    And finally, add your page with the body content:

    PageTitle = "My Title";
        $TPL->ContentBody = __FILE__;
        include "layout.php";
        exit;
    }
    ?>
    

提交回复
热议问题