smarty

PHP framework (cake/smarty): How to use it and when?

▼魔方 西西 提交于 2019-12-05 20:21:59
Duplicate of What is a PHP Framework? and many more So far, I've been using PHP for small tweaks, mostly with WordPress. What are PHP frameworks? Why do I need them? WHEN do I need them? Any insight will be helpful. Thanks. Tim Lytle Frameworks are organized groups of code or libraries, built on top of a language to either Make Common Tasks Easy/Simple Create a Consistent Way to Develop Applications Some frameworks are very restrictive (as in it's not easy to do things, unless you do them the 'framework' way), others are looser. I've found Zend's Framework to be a good mix of both, making easy

Smarty : evaluate a template stored in a PHP variable

时间秒杀一切 提交于 2019-12-05 17:49:15
问题 i have a php variable which has html/smarty code in it $x='<a href="{$link}" >{$title}</a>'; This data is fetched from database , i want to evaluate it using smarty and put the output into a php variable (to print it out or to save it to the database again) . Thanks Edit : i want the content of X to be evaluated using smarty , as if the content of x is stored in a file.tpl then $y=$smarty->fetch('file.tpl'); ... want to do it without the need to save the content of x into a file 回答1: If you

Smarty - 'unable to write file… templates_c'. (smarty_internal_write_file.php:44) [closed]

给你一囗甜甜゛ 提交于 2019-12-05 17:40:56
I'm using Smarty for the first time. It works fine on my laptop (MAMP) but when I try and run a basic template on my production server (Windows) I get this error message: Fatal error: Uncaught exception 'SmartyException' with message 'unable to write file C:\Inetpub\vhosts\path\to\web\root\smarty\templates_c\wrt516e53290e2095.47946913' in C:\Inetpub\vhosts\path\to\web\root\smarty\libs\sysplugins\smarty_internal_write_file.php:44 Stack trace: #0 C:\Inetpub\vhosts\path\to\web\root\smarty\libs\sysplugins\smarty_internal_template.php(201): Smarty_Internal_Write_File::writeFile('C:\Inetpub\vhos...'

Get first Smarty Array-Element

丶灬走出姿态 提交于 2019-12-05 17:29:42
How can i get the first smarty array element ? Actually i know how to do this... but i have following issue. I get a array passed that looks like this [DATA] => Array ( [12] => Array ( [content] => foobar ) [1] => Array ( [content] => ) [2] => Array ( [content] => ) [3] => Array ( [content] => ) //this is a snipit of {$myVar|@print_r} this goes down until [11] For some reason there is no [0] and a [12] at this position. I don't know if this will allways be 12 but I know it allways be at the first position. I can't sort this array because there is another array that has the same sortorder and I

Wrong page number on setPage() function: 0

强颜欢笑 提交于 2019-12-05 15:13:09
My code for tcpdf is $file_to_show_test_details = 'pdf_view_test_details.tpl'; $test_details= $smarty->fetch($file_to_show_test_details); // Set some content to print $html = <<<EOD $test_details EOD; // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'XYZ',$pdf->writeHTML($html, true, false, true, false, '')); The function writeHTML is not working, that's why the error 'Wrong page number on setPage() function: 0' appears in the browser. Could anyone please help me to solve this issue? Did you try to use addPage()? //$pdf = new PDF(); $pdf->AddPage(); For

How to get all assigned Smarty variables while running the template?

血红的双手。 提交于 2019-12-05 13:13:25
I would like to get all variables assigned to Smarty inside the template. For example, if I have this code $smarty->assign('name', 'Fulano'); $smarty->assign('age', '22'); $result = $this->smarty->fetch("file:my.tpl"); I would like to have a my.tpl like the one below: {foreach from=$magic_array_of_variables key=varname item=varvalue} {$varname} is {$varvalue} {/foreach} such as the content of result would be name is Fulano age is 22 So, is there a way to get this $magic_array_of_variables ? all code below is smarty2 All smarty variables are held inside the $smarty->_tpl_vars object, so before

How to print a json in Smarty

泄露秘密 提交于 2019-12-05 10:23:52
Am getting a json from an api, how to print the json using Smarty. Json format [ { "first_name": "jinu", "last_name": "mk", "loginid": "jinu@amt.in", "timezone": "5.5", "team_id": "c964ef415f157ddd99173f5b481ee1e3", "user_type": 1, "last_login_date": null }, { "first_name": "avatar second", "last_name": "test", "loginid": "avatar2@gmail.com", "timezone": "5.5", "team_id": "ec40f5feda8643135bc20be44f897b03", "user_type": "3", "last_login_date": null }, { "first_name": "avatar testing admin", "last_name": "amt 1", "loginid": "avatar@amt.in", "timezone": "5.5", "team_id":

Smarty outputs blank page

旧时模样 提交于 2019-12-05 09:54:57
SOLVED: Error in template file I have Smarty setup like this: require_once 'smarty/Smarty.class.php'; $smarty = new Smarty(); $smarty->compile_dir = $compile_dir; $smarty->template_dir = $tpl_dir; That's all I should need for now... I have Smarty setup exactly like this for another site and it works just fine on the same server. var_dump($smarty) outputs all its public variables and $smarty->template_exists("index.tpl") returns 1 , which would both indicate that Smarty is properly setup and working, however, both $smarty->display("index.tpl") and $output = $smarty->fetch("index.tpl"); echo

Smarty how to get a first index from foreach?

喜欢而已 提交于 2019-12-05 06:07:21
Construction is this: <!-- projects list --> {if !empty($userObjects)} <select id="projects-list" tabindex="1" name="project"> {if !isset($selected)}<option value="0">Choose project</option>{/if} {foreach from=$userObjects item=v} <option value="{$v.Id}" {if $selected==$v.Id}selected="selected"{/if} }>{$v.Name} {* if it's 1st element *} {if $smarty.foreach.v.index == 0} {if isset($limit)}<br /><span id="projlimit">{$limit}</span> {$currency->sign}{/if} {/if} </option> {/foreach} </select> as you can see I did {if $smarty.foreach.v.index == 0} but it's going wrong. In this case all the options

Remove extra HTML spaces in Smarty

假如想象 提交于 2019-12-05 03:46:34
问题 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