Jump to content

Change body id $page_name


Recommended Posts

Hello,

 

How do I change body id only for the file shopping-cart.tpl.

 

Now my body = "$page_name" which value is = "order", but i want it to be something different in relation to some css code.

 

Can I set a specific value for $page_name in relation to one template?

 

Can any help me with this one?

 

Best Regards

Soren Frederiksen

Link to comment
Share on other sites

  • 3 months later...
  • 7 months later...

note: this is how I made it work in prestashop 1.4.6.2 -> don't know how it plays out or if it's even needed in prestashop 1.5

 

Hey guys,

 

The big problem is that prestashop makes order-summary and all the following order steps part of the same "order" controller, and that therefore it gives the same $page_name = "order" to all of these pages.

 

Here's how you can have your header and footer template files know the difference between the "review shopping-cart" step and the other ones, this can also help you give one different page name to each order step.

 

1. You need to override the default behavior of "OrderController": go to the override/controllers/ folder and create a file named "OrderController.php", with this code in it:

 

<?php
class OrderController extends OrderControllerCore
{
// tell the header and footer templates when a user is on the shopping cart / order summary page
public function displayHeader()
{
 if (!Tools::getValue('ajax')){
  if(((int)$this--->step == 0) || ((int)$this->step == -1))
self::$smarty->assign('order_page_name', 'order-summary');
  parent::displayHeader();
 }
}
public function displayFooter()
{
 if (!Tools::getValue('ajax')){
  if(((int)$this->step == 0) || ((int)$this->step == -1))
self::$smarty->assign('order_page_name', 'order-summary');
  parent::displayFooter();
 }
}
}
?>

 

What this does is that it checks to see what step the user is on in the order process, and then assign a special variable (accessible in the header and footer template files) if the step is order-summary (1 or -1).

 

2.Then in the header.tpl and footer.tpl files, I just add a line of code that checks to see if i'm on the order-summary page or not.

Add this line at the very beginning of each header and footer .tpl files (don't forget to close the {/if} at the very bottom of these files too)

 

{if (($page_name == "order") && ($order_page_name == "order-summary"))}
{include file="$tpl_dir/header-order.tpl"}
{else}

 

{if (($page_name == "order") && ($order_page_name == "order-summary"))}
{include file="$tpl_dir/footer-order.tpl"}
{else}

 

That way when the header and footer loads, it will first check to see if I'm on the "order-summary" page of the order process and in that case load a different .tpl file.

 

3. create two new tpl files, "header-order.tpl" and "footer-order.tpl", in your template directory and load anything you want or don't want. Btw, all the hooks and "$css_files" variables will still be accessible from these templates.

 

I hope this can help some people out there, this can be easily extended to load different files for each of the order pages as needed.

Edited by dagobert (see edit history)
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...