smarty

Smarty getting substring of a var with strpos as start and strlen as end

二次信任 提交于 2019-12-04 00:45:55
问题 I am having issue formatting variables in smarty. I was wondering what is the best way to do it. Basically i have a string "ABC | DEFGH" i want smarty to get the substring of "DEFGH" How would i go about doing this? {$var|substr:strpos:"|":strlen} doesn't work 回答1: Just solved this without setting var back in PHP, and by using the built-in function wrappers. Assuming that: $var = "ABC|DEFGH"; {assign var="bar_at" value=$var|strpos:"|"} <li>{$var}</li> <li>{$var|substr:0:$bar_at}</li> <li>{

Remove extra HTML spaces in Smarty

痞子三分冷 提交于 2019-12-03 20:55:47
We heavily use Smarty for all our front end templating. I have observed the following situation: When my Smarty template is similar to as follows: <li> {if $a == 'A'} {$var1} {else} {$var2} {/if} <br><span>SUBTEXT</span> </li> The final HTML which is delivered to the browser is: <li> 65 <br><span>SUBTEXT</span> </li> I would expect it to be more clean and something like: <li> 65<br><span>SUBTEXT</span> </li> or better: <li>65<br><span>SUBTEXT</span></li> Anyway I can do this with some configuration settings in Smarty 3? Any setting to format and clean the final HTML created? Thanks rodneyrehm

Formatting numbers with thousands separator Smarty PHP

旧巷老猫 提交于 2019-12-03 18:38:18
问题 Im trying to format numbers with thousands separator Smarty. So for example 1000 becomes 1,000. Thanks. 回答1: or you can use php function inside smarty, this is for number_format, you can use other php function too :) PHP : number_format($number, 2, '.', ','); SMARTY : {$number|number_format:2:".":","} 回答2: or just in smarty use {$var|number_format:0} 回答3: Try to use string_format, it uses sprintf to format your string. 来源: https://stackoverflow.com/questions/3193710/formatting-numbers-with

Smarty - foreach loop 10 times and stop

你离开我真会死。 提交于 2019-12-03 16:21:35
问题 Im using the following Smarty code: {foreach from=$entries key=i item=topic} {if $topic.topic_style == question} <li> <a href="topic.php?id={$topic.id}">{$topic.title}</a> </li> {/if} {/foreach} How can i do the {foreach} a maximum of 10 times and then stop? 回答1: You can use index and break function: {foreach from=$entries key=i item=topic name=foo} {if $smarty.foreach.foo.index == 10} {break} {/if} {if $topic.topic_style == question} <li> <a href="topic.php?id={$topic.id}">{$topic.title}</a>

Concatenation in smarty

喜你入骨 提交于 2019-12-03 15:22:41
问题 I want to assign the value obtained from the concatenation of these two variables with a string. {assign var="url" value="{$WS_PATH}aircraft_images/{$images[i].image}"} Please let me know how can we do this in smarty. 回答1: One of these should work: {assign var="url" value=$WS_PATH|cat:"aircraft_images/"|cat:$images[i].image} Or {assign var="url" value="`$WS_PATH`aircraft_images/`$images[i].image`"} I am not sure if the $images[i].image will be parsed correctly, you may have to {assign} it to

Smarty integration into the CodeIgniter framework

泄露秘密 提交于 2019-12-03 15:03:56
问题 A Little Background Information : I've been looking at a few PHP framework recently, and it came down to two. The Zend Framework or CodeIgniter. I prefer CodeIgniter, because of its simple design. It's very bare bone, and it is just kept simple. The thing I don't like though is the weak template system. The template system is important for me, because I will be working with another designer. Being able to give him a good template system is a big plus. Zend was the second choice, because of

disable smarty notice

↘锁芯ラ 提交于 2019-12-03 13:55:25
I would like to disable smarty-s notices. This exactly: Notice: Undefined variable: xy Because I know that some variables are undefined and in some cases I don't even want to define them. BUT I don't want to disable other PHP notices. Thanks for help! You should use this: http://www.smarty.net/docs/en/variable.error.reporting.tpl Just set $smarty->error_reporting = E_ALL & ~E_NOTICE; Mohamed Adel El-Badry You should make your checks on the variables and make sure they are defined and set before using. Removing the Notices and Warnings enhance the performance of your application. When your

ThinkPHP框架使用Smarty模板引擎

☆樱花仙子☆ 提交于 2019-12-03 12:20:34
最近公司使用ThinkPHP框架,所以比较关注,想到之前公司使用的框架用的模板引擎是 Smarty,而且用的还挺顺手的。 转到使用ThinkPHP自带的模板引擎还有点不习惯,所以在想换成Smarty模板引擎,网上看了一下,结果还是比较简单。 以此记录一下 首先ThinkPHP框架里面要有Smarty扩展 位置在 ThinkPHP\Extend\Vendor\Smarty ,如果没有就去 Smarty官网下一个最新版吧,也推荐使用最新版的。一般完整版的ThinkPHP框架都含有 Smarty扩展的。 然后只需修改配置文件 Conf\config.php <?phpreturn array( //'配置项'=>'配置值' 'TMPL_ENGINE_TYPE' => 'Smarty', 'TMPL_ENGINE_CONFIG' => array( 'caching' => TRUE, 'template_dir' => TMPL_PATH, 'compile_dir' => TEMP_PATH, 'cache_dir' => CACHE_PATH, 'left_delimiter' => '{', 'right_delimiter' => '}', ), );?> Action: <?phpclass IndexAction extends Action { public

Smarty前端模板引擎

点点圈 提交于 2019-12-03 12:18:24
Smarty Smarty可以说是我接触PHP这门语言用到的第一个开源框架,当时在Smarty的帮助下,很好地完成了项目的开发,也很好地遵循了MVC的模式。但是到了后来,慢慢地发现,很多人都很熟悉Smarty,但是都不愿意使用它。大概的原因在于:慢。 当初以为Smarty很神奇,到后来发现也是通过PHP来实现的。再到后来别人反映使用Smarty会影响性能,所以也就想深入了解一下它的源代码,看下它是怎么实现的,是不是真的会慢? 其实,Smarty只是用PHP做了一个中间层,来把自定义的一些模板标签再转换成PHP语言,这里面涉及到语法树模式和PHP代码的自动生成。 然而,计算机的艺术正在于此:任何的问题,都可以通过一个中间层来实现完成,但也会因此带来性能问题。所以 ,正是这一层中间层,影响了性能。但同时Smarty也努力通过缓存来填补这块的空缺。但对于好的项目分层、分离前端和后端,Smarty在开发实践中确实有好的作用,这就需要项目在人力成本和服务器成本之间做下权衡吧。 UML静态结构 - 部分 Smarty确实对外表现得很优秀,但是,Smarty里面的结构和代码层次,就个人看来,有些凌乱。以下是部分的UML结构图,其他待补充。 分析与总结 同样,由于当时未能实时纪录,这里罗列一些关键 类: Smarty_Internal_CompileBase(编译的标签,如:循环、赋值、中断等)

How to put HTML data into header of tcpdf?

一个人想着一个人 提交于 2019-12-03 09:16:59
问题 I'm using the tcpdf library to generate the pdf document. I'm using smarty template engine to hold the data. Below is the script to put in the header data: // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'PQR', 'XYZ'); I want to put HTML table content of smarty template in place of XYZ, the table content is going to be dynamic(meaning the data in table may vary for each PDF document). 回答1: As @vinzcoco says, you must extend TCPDF to achieve what you want