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

How to display limited characters in smarty?

I am receiving a paragraph content in smarty. While displaying i need to display only 25 characters how to limit characters in smarty.

{$myresult}

Now i am simply displaying. How to display only 25 characters from smarty content
Mohan Ram
  • 8,345
  • 25
  • 81
  • 130
7
votes
4 answers

How can a I get a constant in smarty?

I got a problem with Smarty and constants. I got three constant especified in a file: DEFINE('ARTICLE_COLOUR_10', 'Light green'); DEFINE('ARTICLE_COLOUR_11', 'Claret'); // Bordó DEFINE('ARTICLE_COLOUR_12', 'Yellow'); In DB I save only the numbers…
Marcos Muñoz
  • 73
  • 1
  • 4
7
votes
2 answers

Disabling caching on the PHP Smarty templating engine?

For some reason I can't get Smarty to stop caching templates, which is really annoying when I'm making changes to templates during development. Can someone tell me where I'm going wrong in disabling all caching?: $smarty = new…
Rob
  • 109
  • 1
  • 1
  • 7
7
votes
2 answers

smarty if empty else smarty value

I have smarty value if it empty need another result {get_video_meta video_id=$video_data.id key='test'} This value print "test" If this value is empty else how can I use? {if !empty({get_video_meta video_id=$video_data.id key='test'})} No…
Raj Mohammed
  • 173
  • 1
  • 3
  • 10
7
votes
2 answers

.htaccess Error : Invalid command 'AuthGroupFile'

before this i was working on windows and my project was working proper. recently i moved to ubuntu and i am trying setup project on LAMP. i have created host for this (windows i was running directly through localhost) and when i am running it…
Kalpit
  • 4,906
  • 4
  • 25
  • 43
7
votes
5 answers

How to access key and value of an array in smarty template?

I'm assigning an array named $enquiries_labels from php file to a smarty template file. If I print the array in PHP file it's output is as follows: Array ( [0] => New Enquiry [1] => Retail Enquiry [2] => Feedback [3] => Payment…
PHPLover
  • 1
  • 51
  • 158
  • 311
7
votes
3 answers

Force Smarty to show PHP errors

I've been working with PHP for a while, but fairly new to Smarty. I'm working with Prestashop and I've noticed Smarty seems to eat up all PHP errors - when there's an error in the PHP code, the .tpl file just outputs a blank page. I've been trying…
sveti petar
  • 3,637
  • 13
  • 67
  • 144
6
votes
3 answers

Accessing a variable (local or global) of PHP file from smarty

I have a php file that has some local and global variables (e.g. $foo) an smarty object is called from this file. How can I access $foo from smarty script without changing PHP file? Thanks
Ariyan
  • 14,760
  • 31
  • 112
  • 175
6
votes
1 answer

Is there a i18n/translation solution for Smarty?

I'm developing a PHP-based application that requires internationalization (i18n) support. I'm using Smarty 3 as a template solution (and TinyMVC as the framework), and although I've been using it for small projects before (back in the days of Smarty…
Jimmie Lin
  • 2,205
  • 2
  • 23
  • 35
6
votes
2 answers

Smarty output to PHP Constant is it possible?

I got constant in PHP This constant is written in Mysql With Smarty i am doing output to HTML Is it possible to output Smarty results to php not to HTML ?
Cameleon
  • 453
  • 1
  • 6
  • 16
6
votes
8 answers

Is it worth learning Smarty for PHP templating?

I'm building a simple 10-page site using an MVC-like architecture. Is it worth learning the Smarty templating engine?
Trent Scott
  • 2,018
  • 8
  • 34
  • 50
6
votes
1 answer

How to clear Smarty's Cache

The original owner of our company had the website designed using Smartys. I have updated the product page, but even after deleting the temporary file from "templates_c" which I thought was the cache file, the updated products page will not show up…
user470760
6
votes
3 answers

Smarty Vs. Javascript/AJAX

I have a doubt: - Is there any standard/convention that when should I use "Smarty templating" and when should I use Javascript Ajax calls to produce the content? I can use Ajax/Javascript calls to produce the content dynamically. My application uses…
Sabya
  • 11,534
  • 17
  • 67
  • 94
6
votes
7 answers

Smarty templates: How to change the order of blocks in child template?

I would like to change the order of parent blocks in a child templates while using the content of the parent blocks. Example: parent template: {block outer} {block a} ... some long content ...{/block} {block b} ... some long content…
Leif
  • 1,076
  • 10
  • 16
6
votes
5 answers

What's the difference between Smarty and Zend?

I came upon Smarty which is a template engine. But there are also the Zend, CakePHP frameworks. Is Smarty like Zend, or are they completely different? Smarty just separates logic from display - is this similar to a framework like Zend?
jpjp
  • 585
  • 1
  • 7
  • 15