什么是 .tpl 文件?php, 网页设计
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1808294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is .tpl files? php, web design
提问by Dan
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:
一个人想让我重新设计一个用 PHP (VideoCMS) 运行的网站。但是当我让他给我发送源代码时,他给了我 *.tpl 文件而不是 *.php。它们里面有一些代码:
{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?
问题:代码的解释器是什么?如何重新设计这个网站?
回答by Chris Clarke
That looks like Smarty to me. Smarty is a template parser written in PHP.
对我来说,这看起来像 Smarty。Smarty 是一个用 PHP 编写的模板解析器。
You can read up on how to use Smartyin 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.
如果您无法访问 CMS 的源代码:要在浏览器中查看模板,只需查看 Smarty 使用的变量并创建一个 PHP 文件,用虚拟数据填充使用的变量。
If I remember correctly, once Smarty is set up, you can use:
如果我没记错的话,一旦 Smarty 设置好,您就可以使用:
$smarty->assign('nameofvar', 'some data');
to set the variables.
来设置变量。
回答by Benjamin Crouzier
.tplis the extension for smartyfiles. It means "template".
.tpl是smarty文件的扩展名。它的意思是“模板”。
Tip: if you are using netbeans and you want a correct syntax highlighting for those files:
提示:如果您使用的是 netbeans 并且希望为这些文件正确突出显示语法:
- Go to
options/tools - Under
Miscellaneous, selectFilestab - Click new file extension, enter
tpl. - In
Assiciated file Type (MIME), selectHTML Files (text/html) - Click
ok
- 前往
options/tools - 在 下
Miscellaneous,选择Files选项卡 - 单击新文件扩展名,输入
tpl. - 在 中
Assiciated file Type (MIME),选择HTML Files (text/html) - 点击
ok
回答by paxdiablo
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:
在 Google 上排名第 3 "tpl file"(尽管它是那些令人讨厌的“立即修复 TPL 错误”、“使用我们的病毒扫描程序扫描 TPL 文件”、向您出售所有阳光下的东西并带有浮华丑陋的广告)之一-when-all-you-wanted-was-the-file-description 站点)是:
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.
PHP Web 开发和 PHP Web 应用程序用作模板文件。主要由 Smarty 模板引擎使用。模板是一个常见的文本文件(如 .html 文件),包含用户定义的变量,当 PHP Web 应用程序解析模板文件时,这些变量会被用户定义的输出内容替换。
回答by Sarfraz
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.
这些文件使用某种模板引擎,其中大括号表示由该模板引擎生成的变量,创建此类变量的文件必须存在于其他地方,其名称与 tpl 文件名或多或少相同。以下是一些最常用的模板引擎。
Smarty
聪明的
Savant
学者
Tinybutstrong
小而强壮
etc
等等
With smarty being widely used.
随着 smarty 被广泛使用。
回答by Afridi
You have to learn Smarty syntax, that's a template system.
你必须学习 Smarty 语法,这是一个模板系统。
回答by Paul Dixon
回答by user2908225
.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.
.tpl 显示有一个 smarty !smarty 是一种模板语言,用于将 php 代码从 html 代码中分离出来。这使我们能够在不包含 php 代码的页面上进行设计。
回答by Checo R
回答by serv-inc
Other possibilities for .tpl: HTML::SimpleTemplate, example:
其他可能性.tpl:HTML::SimpleTemplate,例如:
Hello $name
, and Template Toolkit, example:
,和模板工具包,示例:
Hello [% world %]!

