Skip to content
WJunction - Webmaster Forum

Trying to code my own template engine.

Status
Not open for further replies.
Ive got the basics working, it replaces variables.

Now what I need it to do is replace for example {header} with the contents of header.tpl. How would I do that? I'm thinking of trying to use preg_match to do it, but im not too sure how to use it, etc.
Is this the best way to do it?

Thanks,
timtam
 

15 comments

What about:

PHP:
<?php

str_replace('{header}', "<?php include('header.tpl'); ?>", $file_contents);

// Or this ;)

preg_replace('\{header}\\', "<?php include('header.tpl'); ?>", $file_contents);
 
would defeat the purpose, i'd have to define everything. Im trying to get it done dynamically.

eg they could go {somenamehere} and it would load somenamehere.tpl into there
btw ive almost got it working, im just trying to work out recursion now
 
Yeah, I wanna be able to code my own. While I don't mind learning from other people's scripts, I prefer coding and using my own, simply because I don't have to learn their coding stylem and instead I know exactly how it all works.
 
dont do it lol.

Read my tutorial, your trying to reinvent the wheel by using {} or []... just use the slandered php tags and read my template engine tutorial.
 
Read it, im trying for something a bit different. Also, i'm not doing it just because I want a template engine, its more learning the php behind it. I learn by doing stuff, I can't just read a book and learn it, I prefer to code and learn as I'm coding through trial and error
 
well, dont use or invent any new syntax ({}, [] etc..), use classic php
if you will try to implement it with your syntax you will have to develop Cache layout so the app wont have to parse template every time and with that comes much more troubles (not really but its work which is not needed)
 
lmao...

Your learning poor coding tho :( if your going to be learning php, stick to objects, you think sites like facebook,google,youtube,orkut use template engines..... i doubt it.

Listen to the master xD stick to learning objects and speed.
 
actually i think they use some basic like one in Zend Framework (just to separate application logic from interface). But yeah, he is right. Stick to learning objects, OOP is most basic knowledge in this business, you will need it when you will be learning other programming languages ..
 
Status
Not open for further replies.

About the author

T
Active Member · Joined
Picked up photoshop about half a year ago. Now i do graphics design :) Graphics/Web Design
885
Messages
0
Reactions
16
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom