Forum Moderators: coopster

Message Too Old, No Replies

.tpl's and php

are .tpl's preferred for includes?

         

neophyte

1:42 am on Feb 27, 2006 (gmt 0)

10+ Year Member



Hello All -

In order to streamline my workflow, I use a lot of includes to generate headers, footers, and main content.

I have a friend who uses .tpl as the extention to his included files, but he's not able to really explain to me the benefits or drawbacks to a .tpl vs a .php extension.

Can anyone give some insight on this topic? Why one would use one extension vs the other?

Neophyte

jatar_k

3:44 am on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the extension is more for personal clarity than anything else.

tpl sounds like he uses dreamweaver, or used to.

people use many different things, common usage I've seen or heard of

.lib - straight function libraries, no html
.inc - files to be included that contain html
.php - everything else

some people use combination extensions as well

.lib.php
.inc.php
.php

the key to these is you always want all of your php files to be parsed for php otherwise if they are called through a browser they show the source code and that is a bad thing.

neophyte

6:18 am on Feb 27, 2006 (gmt 0)

10+ Year Member



Thanks jatar_k, that clarfies things quite a bit.

And yes, he does use dreamweaver, as do I at this point.

Thanks again.

Neophyte

chrisjoha

7:33 am on Feb 27, 2006 (gmt 0)

10+ Year Member



Also, .tpl is the extension used by Smarty, the PHP template engine.

Cloaking

9:28 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



If a file contains any server-side code, I wouldn't recommend using an extension that is going to result in the code being displayed as plain text on the off-chance someone will attempt to view the file. Unless you've manually altered your web server's settings, this is probably going to be anything other than .php (or, possibly, .phpX).

neophyte

1:12 am on Feb 28, 2006 (gmt 0)

10+ Year Member



Cloaking -

Hummm, some of these .tpl pages do contain php code which indeed are rendered to the browser as plain text if just the .tpl page is loaded.

I am getting use to the .tpl extension and like it because it's easy for me to see that this is an included file (my own issues of ease of organization), but I do want any important code hidden.

when you're talking about altering the server settings can I alter the htaccess file to render .tpl files as .php on the server?

Or, would everyone agree - since there is php code inside most of these files - that it's just better/easier to stick with a .php extension.

Neophyte

SeanW

1:53 am on Feb 28, 2006 (gmt 0)

10+ Year Member



Just to echo what others have said, it's good to keep anything with code in it as .php, or something that'll be parsed by PHP rather than getting sent out plain text.

I used to use .tpl for Smarty templates, now having shortened it to .t. However I keep those outside of the docroot.

Sean

jatar_k

2:41 am on Feb 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could make them

.tpl.php

;)

coopster

4:42 am on Feb 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you ever want to port an application to a shared server that doesn't allow file storage below the document root it is best to name files with the .php extension. Or a combo as mentioned by jatar_k earlier. Just something to consider.

Cloaking

7:56 am on Feb 28, 2006 (gmt 0)

10+ Year Member



neophyte,
It probably would be easier just to stick to naming files .php, but assuming the server your using allows you to do so (which it, if it's a shared server, may not), instructing the server to handle certain files a certain way is a trivial task.

Assuming you are using Apache (it may be similar on other HTTPD servers, but I don't know), and you have access to the httpd.conf file, you could find the line:

AddType application/x-httpd-php .php

And add whatever file extensions you wish to be passed to the PHP engine after the '.php', seperated by a space (it may contain extensions other than just .php).

Otherwise, you can add a handler to a .htaccess file:

AddHandler application/x-httpd-php .blah

Just in case you aren't aware, a .htaccess file has influence over all directories located under the directory it is placed in.

dreamcatcher

8:19 am on Feb 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Savant template engine uses .tpl.php.

Not much use to anyone, just wanted to mention it. ;)

neophyte

12:22 am on Mar 1, 2006 (gmt 0)

10+ Year Member



Thanks to everyone who has weighed in on this topic for me.

After much mental angst, I've decided to drop the .tpl extension and just go for .inc.php as suggested by Jaktar - this way I know it's an include template (of sorts) and any php code with won't be displayed.

Thanks for everyones advice.

Neophyte