Jump to content

Recommended Posts

Hi.

 

I have an HTML template that I'm going to use for my CMS, and need some advice on the best way to split it up into common elements used across all pages.

 

I've identified the common HTML and have written functions to include each. I've used functions instead of directly including them on the page for flexibility in the future.(wise?)

/* functions.php */

function show_style() {
include_once 'module-style.php';
}

function show_header() {
include_once 'module-header.php';
}

function show_sidebar() {
include_once 'module-sidebar.php';
}

function show_footer() {
include_once 'module-footer.php';
}

function show_js() {
include_once 'module-js.php';
}

And then on the page itself...

<?php include_once 'functions.php'; ?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>My CMS</title>
        <meta charset="utf-8">
        
        <?show_style()?>

    </head>
    <body>
        
        <?show_header()?>
        
        <!-- start section content-->
        <section class="section-content">

            <?show_sidebar()?>
 
            <!-- start content -->
            <div class="content">
             
               // PAGE CONTENT
                         
            </div><!--/ end content -->

        </section> <!-- /end section content-->
       
        <?show_footer()?>

        <?show_js()?>

    </body>
</html>

A few questions - are there any issues with using the <? tag as opposed to <?php.... I've seen it used in templating before and want this to be as clean and readable as possible. Also would it be better to use a class for this, and include all of my functions within that class? Any advice or alternatives on the method used above would be great

Edited by paddy_fields
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.