Jump to content

Seperating an HTML template into includes

Recommended Posts



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">
        <title>My CMS</title>
        <meta charset="utf-8">

        <!-- start section content-->
        <section class="section-content">

            <!-- start content -->
            <div class="content">
               // PAGE CONTENT
            </div><!--/ end content -->

        </section> <!-- /end section content-->



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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


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.