Reputation: 3097
After I insert data to database I will set a session and then redirect page to another page, on another page I will show a message if session was set in smarty, everything is ok.
{if $smarty.session.insert===true}
Thanks
{/if}
Now how can I unset the session after I print my message ?
Upvotes: 3
Views: 7178
Reputation: 564
You shouldnt do that in template and smarty hasn't function for this. However, if you really have to do it, the only way around I see could be:
{php}
unset($_SESSION['insert']);
{/php}
Anything you put between {php} tags will be run by smarty as regular php script.
Upvotes: 2
Reputation: 1519
In your php file where you are displaying smarty template, unset it after the display function.
if(isset($_POST['postdata'])) {
$_SESSION['insert'] = 'success';
}
$smarty->display('test.html');
unset($_SESSION['insert']);
In your template file
{if isset($smarty.session.insert)}
{$smarty.session.insert}
{/if}
Upvotes: 0
Reputation: 45124
You really shouldn't do that from a template, do that in PHP like below.
unset($_SESSION['session_var_name']);
If you really want to do it in smart, Have you tried {$smarty.session.message|unset}
I don't know if it works, but it may be worth looking into.
Upvotes: 1
Reputation: 76280
Smarty is a template engine. It is not supposed to handle session variables. You'll have to do unset($_SESSION['...'])
in your PHP script, outside Smarty.
Upvotes: 0