smarty

How to assign an array within a smarty template file?

二次信任 提交于 2019-11-28 08:01:52
I was wondering if it was possible to assign an array to a variable within a Smarty template file? I have tried this {assign var='file' value = array('dir','doc','exe')} But when I print out the array it produces this: array(\'dir\',\'doc\',\'exe\') How can I stop Smarty escaping the array values? Thanks in advance {php} $this->assign("array", array('dir','doc','exe')); {/php} {foreach from=$array item=item} {$item} {/foreach} From Smarty v.3 new syntax is available {$array = ['item1','item2',$item3]} see for more details : http://www.smarty.net/docs/en/language.syntax.variables.tpl I just

php缓存机制的一个讲解

走远了吗. 提交于 2019-11-28 07:12:03
再说 php 缓存机制之前,想来说一下 smarty 的一个缓存小结, 我们可以随便打开一个缓存文件看一下: <body> <h2> 这个说一下缓存集合的一个用法 </h2> 组名 :finance 地址 :beijing 姓名 :phm </body> </html><?php }} ?> 大家注意到没有,缓存文件是不是里面就是已经处理好的代码,他不像编译文件,是 Php 与 html 代码的一个结合体。也就是说这个缓存文件,我们是可以直接拿来就使用的。而它的一个生成原理是什么呢,往下走。 这里先来说一下,用户访问一个 php 页面的时候,后面发生了什么。 当用户访问 php 页面的时候,会向 apache 服务器发出一个请求。而 apache 不认 php 文件里面的东西, Apache 说,它只认识 html, 只会解析返回这个 html 文件。 ok, 那么这个时候,它就会找它的小弟来帮忙,这个小弟就是 php , apache 这个大哥对 php 说, php ,你给老子解析一下这个文件,然后返回一个 html 的文件代码过来,我好返回给用户看 , 不然用户走了,没钱赚了。 ok , 那么这个时候, Php 接到老大的命令,就说,好,大哥,我给你解析一下。这个时候,我们就要进入到 php 的缓存机制里面。 上面的用户请求路线就是下面这种形式: 用户 ->apache-

How to add PHP code to .tpl file [duplicate]

限于喜欢 提交于 2019-11-28 04:25:18
问题 This question already has answers here : Using PHP code in Smarty tpl FIle (4 answers) Closed 3 years ago . I need to display some external data from php file to .tpl file. For this I want to include php file to .tpl file. I have tried folllowing code to display php file content to tpl. {php} include('custom_code.php'); {/php} but on page output was include('custom_code.php'); 回答1: {php} has been deprecated. Have a look at Extending Smarty With Plugins. put the follwing in …/plugins/function

Find where a variable is defined in PHP (And/or SMARTY)?

≯℡__Kan透↙ 提交于 2019-11-28 00:12:40
问题 I'm currently working on a very large project, and am under a lot of pressure to finish it soon, and I'm having a serious problem. The programmer who wrote this last defined variables in a very odd way - the config variables aren't all in the same file, they're spread out across the entire project of over 500 files and 100k+ lines of code, and I'm having a hell of a time figuring out where a certain variable is, so I can fix an issue. Is there a way to track this variable down? I believe he's

Howto generate json with smarty?

梦想的初衷 提交于 2019-11-27 22:11:39
In Smarty, is there a standard function or an easy way to generate json from an array, as json_encode() does in php? Actually It seems there is not in smarty documentation but wanted to ask anyways. Thanks, Sinan. Tom Haigh This should work. The @ makes smarty run the modifier against the whole array, otherwise it does it for each element. {$myarray|@json_encode} If $escape_html is enabled, you will need to use nofilter : {$myarray|@json_encode nofilter} While {$myarray|@json_encode} does in fact emit the array encoded in json, it also escapes special characters, making the array unusable in

Organizing files of a website powered by PHP, Smarty, JavaScript, MySQL

╄→гoц情女王★ 提交于 2019-11-27 19:05:37
问题 I am writing an web application powered by PHP, Smarty, JavaScript, CSS, MySQL. There will be some classes, which will be used through out the application. There will be some scripts which will use those classes. Any good article, tutorial, architecture on how to organize files for a web site? P.S. It should contain how to organize all the files (PHP, JavaScript, CSS, template files.) 回答1: Just remember PHP libraries and template files should not be directly accessible over the web server.

What is the best way to handle recursion in smarty?

家住魔仙堡 提交于 2019-11-27 18:38:01
问题 I found a couple of ways to handle recursion in Smarty, mostly based on including templates into themselves, which seems like ridiculous waste of resources. I found one solution, by Messju over at Smarty that seemed to be just right - but it is not supported and fails in the latest version of smarty :( For people asking: What I want smarty to print out is a discussion thread that is defined by an array of entries. If an entry has one or more answers, those are listed as children to said entry

Using PHP code in Smarty tpl FIle

笑着哭i 提交于 2019-11-27 15:04:48
I am new to smarty and I want to use php code in template file i-e tpl file. I have seen the documentation and searched on google but could not find how to use php code they say we need to configure smarty to allow php execution but could not find how to do it. Kindly help me in this regard. Thanks Easy as boiling an egg! {php}echo "hello!"{/php} Second link down , for reference. Edit as of Smarty 3.1: As of Smarty 3.1 the {php} tags are only available from SmartyBC . Source: http://www.smarty.net/docs/en/language.function.php.tpl softnwords Find the file smarty.class.php in your host

What is .tpl files? php, web design

会有一股神秘感。 提交于 2019-11-27 07:09:20
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=

500 Internal Server Error?

百般思念 提交于 2019-11-27 07:01:35
问题 Recently, I put my project which is php+smarty+mysql in my httpd server. But I encountered an error that says: 500 Internal Server Error My OS is archlinux, and the httpd server and php were installed like this: sudo pacman -S apache php If I use a test native php file which contains the following: <html> <head> <title>PHP Test Page</title> </head> <body> This is Arch Linux, running PHP. <?php phpinfo(); ?> </body> </html> it runs correctly. It tells me that the php can work well. But why is