[Tpl - Templates] A little bit stuck :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IAD
Forum Commoner
Posts: 42
Joined: Wed Dec 28, 2005 12:36 pm
Location: Israel, Soon Canada :)

[Tpl - Templates] A little bit stuck :)

Post 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:
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
IAD
Forum Commoner
Posts: 42
Joined: Wed Dec 28, 2005 12:36 pm
Location: Israel, Soon Canada :)

Post by IAD »

Thanks man, i didn't thought about it :)
Post Reply