Link to home
Start Free TrialLog in
Avatar of aseem1234
aseem1234Flag for United States of America

asked on

How to create cookies using Smarty Template Engine?

Hi,

I have been working with PHP for a decent amount of time, but I now have to work with Smarty at my office. What I am trying to do is create a cookie when someone first comes to the site and then use that variable to display a phone number throughout the site for their entire visit.

I want to use a cookie so that if they close the window and come back later, I can still display the correct phone number targeted for them.

Unfortunately, I don't know anything about Smarty and can't figure out how to create a cookie or access it either. Should I create the cookie using PHP? Can Smarty access cookie data? Can someone help me?

Thanks!


Avatar of prokvk
prokvk

Smarty is a template engine which allows to separate application logic from the output data. Due to this fact you can do really just a few basic operations with Smarty, for anything more complex Smarty allows you to use {php}{/php} tags to implement your logic. So, to your question - COOKIEs via Smarty - definately not. Use pure PHP ;)
Avatar of aseem1234

ASKER

AHHHH So I can use PHP in my Smarty templates by using these {php}{/php} tags? Can Smarty tags be nested inside the PHP tags? And also vice versa?

Thanks!
Also, is there any way to set a cookie in PHP and retrieve it on the same page if the cookie never existed before? I am trying to set a new cookie and have it displayed when a page loads, but it shows up as blank. I have to refresh the page and then the value shows up.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of prokvk
prokvk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of shobinsun
shobinsun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial