Page 1 of 1

PHP TEMPLATES

Posted: Fri May 27, 2005 6:33 am
by shehran
CAN any one tell me how .tpl works with php, its a real confuing topic. :(

Posted: Fri May 27, 2005 10:01 am
by JAM
.tpl is, for me, parts of a template system. The tpl extension is really nothing, but was born (or became most famous) during the creation of Smarty.

If you visit the Smarty homepage and browse around for a while, you'll likely get abit more understanding of it's use.

Posted: Fri May 27, 2005 10:01 am
by pickle
I think generally it's just a file extension people put on template files. .html, .inc, .php, .yourneighborsdog would also work, .tpl is just for humans to look at the file and know what it is.

Posted: Fri May 27, 2005 10:30 am
by Sphen001
Just to note however, is that some editors (ie, Dreamweaver) don't recognize the .tpl extension, so some software (ie, phpBB) have switched back to .html extensions. In the end though, it doesn't really matter. It's just a way of distinguishing templates from other files.

Sphen001

Posted: Fri May 27, 2005 11:02 am
by Burrito
The thing I don't like about .tpl files (at least in so far as phpBB is concerned) is taht you can't include any php scripts in them (by default...I know you can tweak stuff to make it work, but that's more work 8O ).

Look at some other systems that use "themes" like atutor that use just .php files for the template files...you can do whatever you wnat (php-wise) in them which, to me, is a life saver.

I think the .tpl is good for a convention, but that's it. If you put all of your template files in a folder called "templates" or some such and then break down the different themes into subs, you're gonna know what you're dealing with w/o having to look at the file extension.

Posted: Fri May 27, 2005 12:36 pm
by McGruff
You could add two extensions: "foo.tpl.php"

Posted: Fri May 27, 2005 1:33 pm
by RobertGonzalez
.tpl files are the "presentation" portion of your application when you split your applications into "code" and "presentation". These files are usually part of a parsing application (like Smarty or FasTemplates(?)) that are brought into your application just before output to the browser. Generally they have a variable assignment convention like {VAR_NAME} or [%VAR_NAME%] where the templated variable is replaced with the assigned variable from your PHP code. This is done to prevent writing "spaghetti code" where your code and HTML are intertwined and are harder than heck to modify later.

Sometimes developers use other extensions to name template files, such as .inc, .html, .temp, .inc.html, etc. Just make sure you understand that by themselves .tpl files, like .inc files, don't do anything. They are just used as a means to clean up application code by separating code and presentation.

On a side note, I am just about out of quotations marks. Does anyone have any I can "borrow"?

Posted: Fri May 27, 2005 4:28 pm
by neophyte
I name all my template files for Smarty/phpbb/Yapter .html. Why because Dreamweaver and other html editors recognize it. Yeah and my Mac OS X thinks .tpl files are Photoshop Duotone files and so any .tpl that lands in my mac file system is instantly converted to it. There's a lot of things I like about Mac OS X but I could do with out their file/extension management system. So for those reasons I keep the .html extension. There are plenty of projects that don't use templates. It's all personal preference...