-4

I need to access value of $_SESSION['a']['b'] variable using smarty, In other words how can I rewrite this php code in smarty:

if ($_SESSION['a']['b']==1)
{
    do task #1
}
elseif ($_SESSION['a']['b']==2)
{
    do task #2
}

Any suggestions?

user3416269
  • 375
  • 1
  • 5
  • 10
  • Unclear what you're asking? Your code accesses the field, what's your actual problem? Please add what you've tried without success and what unexcpected error/results you get und what you actually expected. Please show your effort. – try-catch-finally Apr 23 '16 at 11:47

1 Answers1

2

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

The request variables such as $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV and $_SESSION are available via the $smarty object.

Grab something from $_SESSION:

{$smarty.session.MY_SESSION_VALUE} //Everything in $_SESSION is available.

Please check this above, you can directly call session in smarty.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Darshan Jain
  • 479
  • 2
  • 10
  • Thanks for your answer, but my session variable is 2 dimensional ! – user3416269 Apr 23 '16 at 09:21
  • @user3416269, First you can print session array then you can just access two dimensional array using dot operator. Hope this helps. If my answer helps then you can up-vote OR accept it. Let me know if you still have any issues. – Darshan Jain Apr 23 '16 at 10:38