What is .tpl files? php, web design

不问归期 提交于 2019-12-17 08:54:40

问题


A man 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}

Question: what's the interpreter of the code? How to redesign this site?


回答1:


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.




回答2:


Templates. I think that is Smarty syntax.




回答3:


.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 options / tools
  • Under Miscellaneous, select Files tab
  • Click new file extension, enter tpl.
  • In Assiciated file Type (MIME), select HTML Files (text/html)
  • Click ok



回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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




回答8:


.tpl shows there is a smarty ! smarty is a template language to split out php codes from html codes. Which gives us to ability to do design stuffs on a page which is not included php codes.




回答9:


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




回答10:


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

Hello $name

, and Template Toolkit, example:

Hello [% world %]!


来源:https://stackoverflow.com/questions/1808294/what-is-tpl-files-php-web-design

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!