Jump to content

Template System


Go to solution Solved by maxxd,

Recommended Posts

Hello there, i'm looking for a way to create a template system, i tried googling but nothing fancy shows up


so my idea is to create a function where i can list the template name and its path in an array

which should looks like this

function template($title) {
    $template = array(
        'header' => include('inc/templates/header.php'),
        'footer' => include('inc/templates/footer.php'),

    return $template[$title];

and in my index page i just call it with variable like <?=template('header');?> or {$header}, whatever works, but it seems like its duplicating my file contents, and some weird integer number at the bottom of the page, so is there an easy way that i can do or a tweak in my code?



Edited by RaiN3772
Link to comment
Share on other sites

1 hour ago, maxxd said:

We don't know what the rest of your code looks like, so it's difficult to say what's actually happening.

My biggest question is is there a reason you're not using one of the many existing PHP template engines? Personally, I'm partial to Twig when not in Laravel land.

didnt know such things existed lol, im newbie to php world, thanks alot mate

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.