Questions tagged [smarty2]

Smarty is a template engine for PHP. It enables programmers and web-designers to implement the MVC architecture pattern. The templates created can be re-used very easily.

Smarty2 is the old version of Smarty templates. If you start with any new project (and have PHP 5.2+) you should always choose Smarty3 instead.

Last Smarty2 version is 2.6.28 and was released on Oct 1st, 2013

Links

106 questions
9
votes
4 answers

Smarty getting substring of a var with strpos as start and strlen as end

I am having issue formatting variables in smarty. I was wondering what is the best way to do it. Basically i have a string "ABC | DEFGH" i want smarty to get the substring of "DEFGH" How would i go about doing…
KJYe.Name
  • 16,969
  • 5
  • 48
  • 63
6
votes
2 answers

Get first Smarty Array-Element

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 ( …
Dwza
  • 6,494
  • 6
  • 41
  • 73
6
votes
3 answers

smarty convert string to number

I need to do deviding: {math equation="x/y" x=$x y=$y} // $x = '2', $y = '3' How to convert strings to numbers exactly in Smarty, coz I don't have access to proprietary code of CMS? Thanx! UPD: Smarty version: 2.6.18
Sergey Kudryashov
  • 713
  • 2
  • 9
  • 30
5
votes
3 answers

How do I create a 'for' loop in Smarty 2?

I would like to know if it is possible to do something similar to a for cycle using Smarty 2. I would like to have something like this: What function should…
nunos
  • 20,479
  • 50
  • 119
  • 154
4
votes
2 answers

{if}{else} do not work properly in smarty

I have following smarty code on my template {capture name="diff"} {datediff timestamp=$data_base.updated_date} {/capture} {$smarty.capture.diff} | {$smarty.const.UPDATE_BLOCK_SECONDS} {if $smarty.capture.diff >…
Prakash
  • 2,749
  • 4
  • 33
  • 43
4
votes
1 answer

How does smarty cache work? How does it know when to cache?

What makes smarty decide if the cache it has is sufficient or if it needs to recreate it? Will the $_REQUEST do? Or all globals including cookies, session and etc... Is index.php and index.php?task=home have the same cache, what about cookies and…
Neo
  • 11,078
  • 2
  • 68
  • 79
4
votes
3 answers

alternative to Smarty {literal} tags for dynamic JavaScript

I have the following Smarty template which is shown in its' entirety which generates some JavaScript. As you can see I am opening {literal} and closing {/literal} tags all throughout this code snippet, which looks a bit messy and unruly. Is there a…
crmpicco
  • 16,605
  • 26
  • 134
  • 210
4
votes
1 answer

How do I check if file exists in Smarty 2

How do I check if file exists in Smarty 2? I mean something like this: {assign var="module_js" value="/js/modules/{$module}.js"} {if file_exists($module_js)} {/if}
Yekver
  • 4,985
  • 7
  • 32
  • 49
3
votes
2 answers

Upgrading Smarty from Smarty v2 to v3

I am in the process of upgrading a PHP-based site from Smarty2 to Smarty3. I have managed to get most everything working on both versions by replacing require_once('Smarty.class.php' with the following: @ include_once('SmartyBC.class.php'); if…
undefined
  • 6,208
  • 3
  • 49
  • 59
2
votes
3 answers

How can i check if image file exists on smarty using URL?

I want to check if the webp image is exists on the server on smarty. The URL is an absolute URL like this. i tried {if file_exists("https://example.com/image.webp")} {/if} and {if 'https://example.com/image.webp'} {/if} But none is working. Can…
2
votes
1 answer

Smarty template engine is not running foreach

the foreach method is not working properly in the smarty template engine. Can you show how it might look using a while loop // Foreach data in post array saved : add a new input in the redirection form foreach($_SESSION['POSTDATA'] as $key =>…
2
votes
2 answers

Grabbing certain values from an array in Smarty

I have been trying this for hours, If it was just PHP I would be done by now but this requires Smarty 3 so things are a little different. I am having difficulty grabbing specific keys plural from an Array. The Array looks like this Array ( [0]…
Steini Petur
  • 129
  • 1
  • 9
2
votes
3 answers

Generate distinct smarty random numbers

I'm using smarty v2.6 and I want to generate random distinct numbers. I'm looking for an efficient, fast way to do it using already provided Smarty functions. This is my code for generating 5 random numbers (but not distinct): {assign var=min…
George Chalhoub
  • 14,968
  • 3
  • 38
  • 61
2
votes
1 answer

Smarty 2.6.14 and PHP 5.4.9 doesn't recognize {literal} tag

I've a html page with php smarty tags. The problem is the {literal} tags, needed to escape javascript and css code block. In many others php versions, like php 5.3 or 5.5 works fine, but in php 5.4.9 doesn't work When i use {literal} to escape…
Thiago França
  • 1,817
  • 1
  • 15
  • 20
2
votes
3 answers

assign variable value on one line with Smarty 2

I am using Smarty 2 and wondered if there is a better/tidier way to use assign to set the value of evenRow on one line, rather than the 5 lines below. {if $evenRow == 'on'} {assign var='evenRow' value='off'} {else} {assign var='evenRow'…
crmpicco
  • 16,605
  • 26
  • 134
  • 210
1
2 3 4 5 6 7 8