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
2 answers

Using plugin functions in Smarty foreach

I've been experimenting with Smarty lately a bit (first time into using this kind of stuff), and I have a quick question I just can't figure out.. I have created a function for Smarty, called get_users(), so it'd be {get_users} into my .tpl I want…
Mauro Casas
  • 2,235
  • 1
  • 13
  • 15
1
vote
1 answer

PHP functions and variable scope in Smarty

I'm working within Smarty 2.6.27. There is something that prevents PHP functions from accessing global variables: {php} $a = "should be global"; function test(){ global $a; echo $a; } test(); {/php} But the variable $a never makes…
brentonstrine
  • 21,694
  • 25
  • 74
  • 120
1
vote
1 answer

Every occurrence, but more complicated

Basically this code gives me < li > 1 2 3 4 < / li > < li > 1 2 3 4 < / li > < li > 1 2 < / li >. So basically at end i need to put 3 and 4 with different result for example, < li >1 2 empty empty< / li > - since there should be always 4 results per…
Cameleon
  • 59
  • 10
1
vote
4 answers
1
vote
0 answers

Prestashop search module doesnt work after adding www. to my shopdomain

Since I added www. before my shop domain my search module doesn’t work anymore. It seems that the url request stays in a loop. All other pages works fine with the www. addition. The search page appear well without the rewrite and the the url is like…
Dinizworld
  • 394
  • 1
  • 6
  • 16
1
vote
2 answers

How to insert more than one value for a select dropdown

I can't seem to find a workaround for this. I have a smarty based script that im using. I am trying somehow submit 2 values from a form that is on my submit post page. I am actually successfully posting several fields into the "posts" table…
Zack Bluem
  • 83
  • 1
  • 2
  • 11
1
vote
2 answers

Hide element based on the value of select name option?

I want get the value from the select name and when the value will be somthing, take some action. All value are save in pdo db. Html:
Something
Code: