smarty

smarty replace line breaks

拜拜、爱过 提交于 2019-12-10 17:57:17
问题 At the time of writing this, the smarty.net website appears to be down. Anyway, how do I replace line breaks with a space in a smarty variable? Is it something like this {$var|regex_replace:'[\\r\\n]':'\s'} ? I tried it but it didn't work. 回答1: Try this if it works: {$var|regex_replace:"/[\r\n]/" : " "} 来源: https://stackoverflow.com/questions/6078804/smarty-replace-line-breaks

Smarty nested for-each with array

╄→尐↘猪︶ㄣ 提交于 2019-12-10 15:24:57
问题 I'm having a little trouble with Smart for-each loops - here's my code: {* this example will print out all the values of the $custid array *} {foreach from=$order_info item=amount} amount: {$amount}<br> {/foreach} So basically I'm just trying to loop through and print the "amount" from $order_info - the problem is, it just prints the whole array and not just the "amount". Here's a reduced number of items from the array that I got from the debug console: {$order_info} Array (86) order_id =>

Compare two dates in smarty

牧云@^-^@ 提交于 2019-12-10 12:21:17
问题 I have two dates in respective format (02-Dec-14 and 17-Dec-14 ) and i want to compare these two dates in smarty. How can i compare these two dates ? please help. Thanks In Advance 回答1: If you have those dates assigned to Smarty for example this way: $smarty->assign('date2','02-Dec-14'); $smarty->assign('date1','17-Dec-14'); you can use strtotime function directly in Smarty, for example: {if $date1|strtotime < $date2|strtotime} {$date1} is earlier than {$date2} {elseif $date1|strtotime ==

Calling Smarties display() method multiple times vs using includes

拈花ヽ惹草 提交于 2019-12-10 11:26:54
问题 Which method of pulling together the templated parts of my site is best practice? I prefer the first solution, but I'm not sure using multiple calls to display() is good practice. I'm looking for ease of maintenance and speed. <?php $smarty->display('header.tpl'); $smarty->display('menu.tpl'); $smarty->display('article1.tpl'); $smarty->display('footer.tpl'); ?> or displaying a single smarty template and then within the template having {include file="header.tpl"} <body id={$pageid}> {include

laravel实践

不羁岁月 提交于 2019-12-10 11:23:44
laravel实践 smarty 将压缩包解压后,将libs文件夹拷贝到项目的根目录下,并重命名为smarty,然后在控制器类中引入Smarty.class.php 创建模型 <?php class NewsModel { function list ( ) { $dns = "mysql:host=localhost;dbname=test" ; $user = 'root' ; $password = 'root' ; $pdo = new PDO ( $dns , $user , $password ) ; $res = $pdo - > query ( "select * from news" ) ; $news = $res - > fetchAll ( PDO : : FETCH_ASSOC ) ; return $news ; } } ### 创建控制器类 ```php <?php include 'smarty/Smarty.class.php' ; include 'NewsModel.php' ; class NewsController { // 显示所有的新闻数据 public function index ( ) { // 创建NewsModel类的对象 $model = new NewsModel ( ) ; 9 $news = $model - >

Smarty Regular Expression Match

☆樱花仙子☆ 提交于 2019-12-10 09:37:01
问题 I Have a smarty variable, I want to know if it matches some string like "<whatever>_thestring_<whatever>" where <whatever> represents any sequence of characters (or no characters). Is there some way to test against something like *_thestring_* ? 回答1: Using smarty to check if a string exists inside another string: {assign "haystack1" "whatever_thestring_whatever"} {assign "haystack2" "whatever_thestrings_whatever"} Test haystack1 {if $haystack1|strstr:"_thestring_"}Found!{/if}<br /> Test

基于Yaf的代码级别扩充--001

二次信任 提交于 2019-12-09 19:03:47
Yaf一个基于C语言实现的MVC框架,其性能不言而喻非常的强悍,Yaf提供的基本的MVC、路由、视图、插件等功能,如果要想很好利用Yaf进行开发的话需要做很多方面的扩充,由于要用到这个框架分享一下自己的一部分扩展剩下还会慢慢的补充扩展。 1:整个Yaf的目录结构如下: [root@lmlq yaf_expand_01]# tree -d ├── application │ ├── actions │ ├── cache │ │ └── templates_c │ ├── controllers │ ├── library │ │ ├── Db │ │ ├── Smarty │ │ │ ├── plugins │ │ │ └── sysplugins │ │ └── Sys │ ├── models │ │ └── Gongchanginfo │ ├── modules │ │ ├── Index │ │ └── User │ │ ├── controllers │ │ └── views │ ├── plugins │ └── views └── conf └── index.php 目录结构中的代码如下: 2:入口文件:index.php <?php /**定义项目中用到的常量**/ define('APPLICATION_PATH', dirname(__FILE__));/

Smarty If URL Contains

狂风中的少年 提交于 2019-12-09 15:37:30
问题 Using Smarty Tags I'd like to determine if an URL contains a word, something like: {if $smarty.get.page contains "product.php"} ..... I know contains doesn't exist, but how could I easily go about writing something similar to achieve the above code? 回答1: You can use strpos to check if a string has another string inside of it. $pos = strpos($smarty.get.page, "product.php"); if($pos !== false) { // found, do something } Except you need to wrap it in {php} and {/php} . $smarty.get.page

Smarty Modifier filesize

狂风中的少年 提交于 2019-12-09 08:11:07
问题 I am using Smarty and one of my section shows file names, including dates, file size, last access etc... I want to display the size of the file in K if less then 1024, in Mb if less than 1048576 etc... The data (file info) comes from the database (name, file size, date etc...) ex: File Mime Size Date Filename1.jpg mime/jpg 14.1Kb 2011/12/12 Is there any modifier in Smarty that do this? Thanks 回答1: create a file in the plugin directory called: modifier.filesize.php then add this code: <?php /*

using smarty with codeigniter

早过忘川 提交于 2019-12-08 18:30:38
I wants to use codeigniter and smarty together.i.e. I wants to use html files instead of .tpl.php files of codeigniter as of smarty. Is this possible or how can I do this.I have searched a lot and find some examples but none of some works as required by me. You should create a library Smarty_tpl.php : <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); //smarty class require BASEPATH . "../../smarty/libs/Smarty.class.php"; class Smarty_tpl extends Smarty { function __construct(){ parent::__construct(); $smarty_dir = BASEPATH . "../../smarty/libs/"; $this->setTemplateDir