Built - in Functions :

Smarty comes with several built-in functions. Built-in functions are integral to the template language. You cannot create custom functions with the same names, nor can you modify built-in functions. Some of the built-in functions are given below.

Important :

The functions having '*' mark are not work in smarty of version 2

include

capture

math

if, elseif, else

literal

function*

while*

for, forelse*

foreach, foreachelse

foreach key

section, sectionelse

Difference between section and foreach

Question for Smarty

  1. Suppose I have two files include_parent.tpl.html and include_child.tpl.html
    Write down the code to include the file only once so that when I am trying to include the file more than once it will show me message.
  2. Find the value of the expression (b-(a+c*(e/d))) in smarty. Where
    a=1,b=2,c=3,d=4,e=8.
  3. What will be the output: x=4
    y=8
    y=y/x
    if(y==2){
    z=(x+y)*(y/z)
    }
    Do it in smarty.
  4. I have div in a html file and i have passed the value of variable $country as India
    Write the javascript code so that i have the output as India is a beautiful country by using the $country variable.
  5. I have an array as
    $a=array('a'=>array(a1=>array(a11,a12,a13)),'b'=>array(b1=>array(b11,b12,b13)),'c'=>array(c1=>array(c11,c12,c13))); Write the code in smarty so that I have the output as
    a11 a12 a13
    b11 b12 b13
    c11 c12 c13
  6. I have an array as
    $a=array(0=>array('name'=>'lalit','address'=>'puri','age'=>24),1=>array('name'='amar','address'=>'tata','age'=>24)); Write the code in smarty so that I have the output as
    lalit puri 24
    amar tata 24
After editing Click here:
Php Code :
Output:
Hello World
Smarty Code :