PHP template class with variables?

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-04-01T23:51:46Z Indexed on 2010/04/02 0:13 UTC
Read the original article Hit count: 662

Filed under:
|
|
|

I want to make developing on my new projects easier, and I wanted a bare bones very simple template engine solution. I looked around on the net and everything is either too bloated, or makes me cringe.

My HTML files will be like so:

<html>
    <head>
        <title>{PAGE_TITLE}</title>
    </head>
    <body>
        <h1>{PAGE_HEADER}</h1>
        <p>Some random content that is likely not to be parsed with PHP.</p>
    </body>
</html>

Obviously, I want to replace {PAGE_TITLE} and {PAGE_HEADER} with something I set with PHP. Like this:

<?php

    $pageElements = array(
                            '{PAGE_TITLE}' => 'Some random title.',
                            '{PAGE_HEADER}' => 'A page header!'
                         );

?>

And I'd use something like str_replace and load the replaced HTML into a string, then print it to the page? This is what I'm on the path towards doing at the moment... does anyone have any advice or a way I can do this better?

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about template