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

<?php
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?

 

thanks

Edited by RaiN3772
Link to comment
https://forums.phpfreaks.com/topic/314197-template-system/
Share on other sites

  • Solution

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.

Link to comment
https://forums.phpfreaks.com/topic/314197-template-system/#findComment-1591907
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
https://forums.phpfreaks.com/topic/314197-template-system/#findComment-1591908
Share on other sites

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.