Jump to content

[Solved] Best way to add php in .tpl


klmiop

Recommended Posts

Hellooooooooo

 

I'm actually trying to make a little thing : 

 

I'm adding a fixed bloc at the top of my prestashop website, and i want to display some informations inside.

 

So i went in the header.tpl in my theme folder, and i added my div right after the <body> tag, and my div is displaying fine. 

 

Now, i want to display some text depending of the content of $_SESSION['foo']

 

If $_SESSION['foo'] is empty, i will display a link, else i will display it's value.

 

I already have the php code ready, but i'm getting troubles to make it worki in a .tpl

 

I've read about the {include file} or the {php} {/php} tags, but it seems not to be working or not beeing a good thing to do, i read that the best way would be to add my logical php treatement inside a controller.

 

My question is, where should i add my php code ? i know i can assign variables to smarty and then display them easily in a .tpl, but i need to make some php processing before.

 

Thanks in advance for reading and for those who could try to help me.

 

Best regards

Edited by klmiop (see edit history)
Link to comment
Share on other sites

{php} {/php} is no longer allowed in version 3 of Smarty. So, as Prestashop has been using that version for quite some time that is not an option.

 

You should be able to access your session variable in Smarty as {$smarty.session.foo}

 

I don't have experience implementing php code for header.tpl, but I would consider using config.inc.php.

  • Like 1
Link to comment
Share on other sites

{php} {/php} is no longer allowed in version 3 of Smarty. So, as Prestashop has been using that version for quite some time that is not an option.

 

You should be able to access your session variable in Smarty as {$smarty.session.foo}

 

I don't have experience implementing php code for header.tpl, but I would consider using config.inc.php.

 

I read you could change the smarty.Class to include for something like smartyBC for backwards compatibilty, but it sounded a bit dirty. 

So i ended adding my php processing in the config.inc.php, not sure if it's the best place, but it's working, there i'm making some tests, then i just assign some variables with smarty->assign and i can display them easily in my header.tpl

 

 

why session? you can use cookie instead? or you want to store some important datas in session variable?

 

Humm no specific reason, i just went for cookies instead, and it's working like a charm !

 

 

I'm really thankfull for you guys to responds so quickly :)

 

I'm changing this to solved, thanks for the help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...