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

Get last N elements from array in smarty

how to get last 7 element of php array in smarty ? I wrote code to get last element {foreach from=$results item=result name=forsmart} {if $smarty.foreach.forsmart.last} …
woj_jas
  • 1,092
  • 7
  • 23
  • 50
1
vote
1 answer

How to change the pagination settings in smarty?

Following is the PHP code of a smarty plugin to apply pagination to the pages.
user2838698
1
vote
3 answers

Prestashop how do i set a module for a single cms page?

I have a module named 'video gallery'. I want it to set for a cms page "video" only . The cms page id is '12' . I have tried {if $cms->id == 12} in video_gallery.tpl doesnt work. Someone please help me thank you!
user1708597
  • 101
  • 5
  • 10
1
vote
1 answer

List Alphabet A-Z in Smarty

I was searching for the web, but I only found a smarty plugin function for displaying the Alphabet from A to Z. There are cases, when you couldn't add a new plugin, so how could you display it otherwise?
bokorben
  • 161
  • 1
  • 8
1
vote
1 answer

how to implement Vista-Like Ajax Calendar to website with smarty template engine

hello people I have s problem with implementing Vista-Like Ajax Calendar to my website. To header.tpl add this lines:
Flambar
  • 11
  • 1
1
vote
2 answers

CodeIgniter not working with multiple level subfolders for both controllers and views

I am working in Codeigniter with smarty templates. Problem is that if i go about 2nd subfolder in view or controller, the Codeigniter stops working... e-g here application/controllers/main.php - works application/controllers/admin/dashboard.php -…
Sizzling Code
  • 5,932
  • 18
  • 81
  • 138
1
vote
1 answer

Objects in Smarty dynamic select field

I want to create a select dropdown list populated with the Categories array that I put inside an array. $contents is an array whose entries are automatically assigned in smarty. foreach ($contents as $key => $value) { …
Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53
1
vote
1 answer

How to remove duplicate values on array using Smarty

I have an array that have duplicated values, I want to print the value only once no matter how many time it exist on the array. This is the code that I have: {foreach item="item" from=$root.page.news.item } {foreach from=$item.Tags item=tagitem…
Saymon
  • 510
  • 9
  • 20
1
vote
2 answers

How can i get SERVER['DOCUMENT_ROOT'] in prestashop tpl page

Can any one help me? I need document_root variable value in tpl page. I am using presta shop as framework. Is there any way to get it?
user3247499
  • 13
  • 1
  • 3
1
vote
1 answer

display 3 images per row

I want to display 3 images per row. but the code show first row with 2(two) images then it shows 3 images next row. where is the problem of the code? …
prasun
  • 63
  • 8
1
vote
2 answers

Is there a way in Smarty to get the file extension of a string

Since we can get the file extension in php by using the explode function or in_array check. Is there a way in Smarty to get the file extension of a string. But how can we get the file extension in tpl page using smarty?currently i am passing all…
ArunJaganathan
  • 695
  • 2
  • 7
  • 20
1
vote
1 answer

How to get a Unix Timestamp from a specific date - PHP?

The Unix Time Stamp generated by my MKTIME is not generating correctly (European format) Date Submitted: 15/02/2014 19:00 Unix Code: 1392508800 This returned date is: 16/02/2014 00:00:00 Code it should of returned is: 1392490800 Code Used After…
DataCure
  • 425
  • 2
  • 15
1
vote
1 answer

Smarty displays raw HTML

I am passing my HTML string to the $content variable and trying to display it, in the result I see raw HTML tags instead of the string markup. Controller: $content = "Test markup"; index.tpl: {$content} - displays just raw variable…
Lucas
  • 3,517
  • 13
  • 46
  • 75
1
vote
1 answer

How to limit output items per @page using smarty template

I have a table of items. But it's over 25 items. What is needed is that the first 25 items will be outputted in a page. then the remaining items will be outputted to another page. That would only be seen when you print the html file. I'm using…
nicole101
  • 187
  • 3
  • 20
1
vote
2 answers

Getting percentage of conversions in Smarty template?

I have two different variables in my smarty template: {$visitors} - Shows the number of clicks on a link. {$numitems} - Show the number of signups from the clicks. I need to get the conversion rate as a percentage which mathematically would be…
user3205164
  • 15
  • 1
  • 4