Page 1 of 1

[Tpl - Templates] A little bit stuck :)

Posted: Wed Dec 28, 2005 12:56 pm
by IAD
Hey,

I just started my own Php based forum, and i just got stucked with the Templates Files.

Why?

When i have couple of chars, for example: "#boards" and i want it to be replaced with the file "boards.php" i can't use regular file's function like: file_get_contents and fopem.
I thought to try use include's or require's functions but there will be always problem.

So what can i do?
Is the any other way to open and replace Tpl's content with Php code files?
Or is there any way to make include not printing the file's output before i'll write "print/echo" [some how deleting "return" option].

Thank in advance - Tal.


P.S if you see any english mistake, please correct me, thanks :P :oops: :wink:

Posted: Wed Dec 28, 2005 1:07 pm
by Ambush Commander
I assume you've got a system somewhat like this:

Code: Select all

echo file_get_contents('template.tpl');
What you're doing is reading a file into a string, then echo'ing it. This is equivalent:

Code: Select all

$string = file_get_contents('template.tpl');
echo $string;
You then manipulate the string, performing the substitution with functions like str_replace(). include and require are for including other PHP code and won't work unless your macro substitution is based of PHP: i.e. #boards becomes <?php echo $urls->getBoards(); ?>

A bit of code would help.

Posted: Wed Dec 28, 2005 1:19 pm
by IAD
Thanks man, i didn't thought about it :)