112

Someone wants me to redesign a site run in PHP (VideoCMS). But when I asked him to send me the source he has given me *.tpl files instead of *.php. There is some code inside them:

{include file='header.tpl' p="article"}

<br />
<table width="886" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150" valign="top">
    <div id="reg_box">
    <h3 class="captions">{$lang.articles}</h3>
        <div id="list_cats">
        <ul>
            {$article_categories}
        </ul>
        </div>
    </div>
    <br />
    <div id="reg_box">
    <h3 class="captions">{$lang.members}</h3>
    {if $logged_in == '1'}
    {include file='loggedin_body.tpl'}
    {else}
    {include file='login_body.tpl'}
    {/if}

or

{include file='header.tpl' p="index"}

{php} $_SESSION['isFair'] = "Yes"; {/php}

What's the interpreter of the code? How can I redesign this site?

10 Answers 10

111

That looks like Smarty to me. Smarty is a template parser written in PHP.

You can read up on how to use Smarty in the documentation.

If you can't get access to the CMS's source: To view the templates in your browser, just look at what variables Smarty is using and create a PHP file that populates the used variables with dummy data.

If I remember correctly, once Smarty is set up, you can use:

$smarty->assign('nameofvar', 'some data');

to set the variables.

1
  • 30
    .tpl is NOT only the extension for smarty files. Many other parsers and in fact custom solutions use .tpl Also if custom, you can place PHP inside the .tpl files too. OpenCart is a good example of this and vBulletin, where inside the .tpl you have have PHP inside it. That is why many servers such as NGINX come pre-built with preventing people from viewing the .tpl files. Jan 6, 2015 at 10:15
29

Templates. I think that is Smarty syntax.

1
  • 1
    2023, yet here I am digging ancient codes. Dec 14, 2023 at 14:54
19

.tpl is the extension for Smarty files. It means "template".

Tip: if you are using NetBeans and you want a correct syntax highlighting for those files:

  • Go to menu OptionsTools
  • Under Miscellaneous, select the Files tab
  • Click new file extension, enter tpl.
  • In Associated File Type (MIME), select HTML Files (text/html)
  • Click OK
1
  • 7
    .tpl is not only the extension for smarty files. Many other parsers and in fact custom solutions use .tpl Jan 6, 2015 at 10:14
13

Number 3 hit on Google for "tpl file" (even though it's one of those annoying "Fix TPL errors now", "Scan TPL files with our virus scanner", sell-you-everything-under-the-sun-with-flashy-ugly-ads-when-all-you-wanted-was-the-file-description sites) is:

Used by PHP web development and PHP web applications as a template file. Mostly used by Smarty template engine. Template is a common text file (like .html file) and contains user defined variables that are replaced by user defined output content when PHP web application parsing a template file.

3
  • 2
    actually searching "tpl file" and clicking on the third result is want brought me to this question...
    – MoralCode
    Jul 15, 2015 at 18:33
  • 2
    When answering a question, it is better to include the link directly instead of relying on Google SERP, which varies from browser to browser depending on user settings and location as well. In addition to this, it is not guaranteed that the result will always be on the same rank. This post is from the year 2009, where as I have seen this in 2017. Today it is of little use. Jul 25, 2017 at 16:11
  • 2
    @Mohammed, I didn't rely on Google always returning the same thing. The whole reason for me copying the text into this answer is so that the answer would still be valid even if Google disappeared off the face of the planet.
    – paxdiablo
    Jul 26, 2017 at 12:02
6

The files are using some sort of template engine in which curly braces indicate variables being generated by that templating engine, the files creating such variables must be present elsewhere with the more or less same name as the tpl file name. Here are some of templates engine mostly used.

Smarty

Savant

Tinybutstrong

etc

With smarty being widely used.

4

In this specific case it is Smarty, but it could also be Jinja2 templates. They usually also have a .tpl extension.

3

Those look like Smarty templates. There should be some additional PHP scripts which actually instantiate the Smarty engine and give it the data it can use for the replaceable elements.

3

You have to learn Smarty syntax. That's a template system.

3

.tpl shows there is a smarty! Smarty is a template language to split out PHP code from HTML code. Which gives us to the ability to do design stuff on a page which has not included PHP code.

0

Other possibilities for .tpl: HTML::SimpleTemplate, example:

Hello $name

, and Template Toolkit, example:

Hello [% world %]!

Not the answer you're looking for? Browse other questions tagged or ask your own question.