Questions tagged [smarty]

Smarty is a templating engine for PHP. It allows for easy separation of application logic and display code, as well as simplifying reuse of templates.

Overview

Smarty templating engine for PHP lets easily separate application logic and presentation, the first being in PHP code and the other generally, but not always, in HTML. That way a separation of PHP and HTML code is encouraged.

Currently two versions of Smarty are maintained for legacy purposes that is compatible with PHP 7.2, and that is compatible with PHP 7.3 and PHP 7.4.

As of April 13th 2020, current Smarty releases are 3.1.35 and 2.6.31

Example

PHP script (example.php) :

require_once('../smarty/Smarty.class.php');
$se = new Smarty();

$se->assign('pi', 3.14159);
$se->assign(array(
    'title' => 'Hello World !',
    'today' => date('d/m/Y'),
));

$se->display('example.tpl');

Template (example.tpl) :

<!DOCTYPE html>
<html>
  <head>
    <title>Smarty example</title>
  </head>
  <body>
    <p>{$title}</p>
    <p>Pi value : {$pi}</p>
    <p>Today is : {$today}</p>
  </body>
</html>

Links:

4490 questions
1
vote
1 answer

submitting via jquery (smarty)

im using SMARTY and php4. (cant upgrade...) i have two selects where i move contet which i get from database from one select to the other with buttons like this : |<<| |>>| using jquery. Now my problem is submitting everything which is in the…
1
vote
1 answer

Smarty adds unnecessary number with foreach?

Im debugging a variable: {foreach from=$menuItems item=row} {$row|@print_r} {/foreach} this prints Array ([parent_id] => 0) 1 Array ( [parent_id] => 5) so far so good. I have to iterate it, but {foreach from=$menuItems…
John Smith
  • 6,129
  • 12
  • 68
  • 123
1
vote
1 answer

Smarty and objects private properties

Smarty allows to access object properties using this syntax in templates: {$object->property} But (If I understood this correctly) this is possible only if property visibility is public, otherwise it seems that Smarty won't be able to access it. In…
Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53
1
vote
4 answers

How to access hidden field's value?

I'm using smarty template and my code is as follows:
PHPLover
  • 1
  • 51
  • 158
  • 311
1
vote
1 answer

smarty code definition {display

I can't understand this code {display property=$theField.id} This code snippet is from smartjobboard cms file is templates/_system/builder/bf_displaylisting_fieldsblocks.tpl line 91 after parsing it produces this echo…
ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58
1
vote
1 answer

Prestashop: how to write a non-hardcoded url to a category?

I'm developing a Prestashop-based website locally. I'm configuring the "slider" module (homepage image slideshow), and it is asking me a URL for each picture. I would like each picture to redirect me to the related category page when clicked…
nadir
  • 1,223
  • 4
  • 12
  • 21
1
vote
1 answer

Smarty data upper limit

I am using Smarty to create a table from a big data set (so it can be loaded as excel file) but the table html code get truncated in the middle. What is the upper limited of data feed to Smarty and how can I set it?
1
vote
2 answers

Smarty foreach iteration in odd steps

My code:
This works fine: {if $smarty.foreach.aussen.iteration % 4 == 0} omega {/if} But I need a…
giller
  • 35
  • 5
1
vote
0 answers

How to add Smarty in wamp php.ini file

I need to add libs for smarty in php.ini, but do I find which file I have to add, where can I find the sub directory being included in php directory..... I have the following error when trying to access the pages on my site in wamp: Warning:…
1
vote
1 answer

PHP Fatal error: Smarty error: syntax error: unidentified token '='

Could someone point me in the right direction. {if $current_url == '/movies' || $current_url == '/tv-shows' || $current_url == '/movie/$mov.title|replace:' ':'-''} Could someone tell me what i'm doing wrong to get this error because i'm new to…
mike jones
  • 101
  • 1
  • 2
  • 13
1
vote
2 answers

Replacing Or Stripping Special Characters With Regex (Smarty)

in a part of my website i have a url that looks like this: http://www.webizzi.com/mp3/search.html?q=+Hush+Hush+-+(Avril)++Lavigne's+ I would like to keep a cleaner url by stripping every special character that appears on the url except + but i also…
1
vote
2 answers

Smarty Template Variable inside Variable

I have text this stored in my database: Your email is: {$email} and your name is {$name}. $text = get from db this field; I read this field from the database I assign with smarty this: $smarty->assign('text', $text); $smarty->assign($name,…
MindTheGap
  • 183
  • 2
  • 14
1
vote
1 answer

How to create a loop in smarty? Ex: for loop, while, do while and also switch statements

I just want to ask how can I include a loop in smarty template? For example a simple for loop and a while loop. I read in the documents but I found nothing. I am a beginner in smarty. So if there's a link for the documentation for that please…
Jerielle
  • 7,144
  • 29
  • 98
  • 164
1
vote
1 answer

Smarty: cannot replace string

I'm new to Smarty and I have a variable which contains a URL http://someurl.com and I'm trying to perform a replace operation on it, to show http://m.someurl.com. This is what I have, but it's not working. {$theurl | replace: 'http://'…
Augusto
  • 779
  • 5
  • 18
1
vote
1 answer

Order array on javascript function

Hello i have this smarty code that generate a list of state in determinate country ordered by states ISO CODE countries = new Array(); {foreach from=$countries item='country'} {if isset($country.states)} …
user1499315
  • 139
  • 1
  • 1
  • 8
1 2 3
99
100