Jump to content

php function to get equivalent to smarty $page_name?


Recommended Posts

Hello everybody, 

I'm trying to create a module that will show a fullscreen slideshow on the home page and a fullscreen background image (no slideshow) on other pages based on category thumbnail.

For the homepage, I use supersize jquery. It seems the supersize js file, when declared, create some divs and a preview wheel appears on every page. I would like to prevent this by declaring the supersize js file only on the homepage. 

So on the module root folder, I have my_module.php file in which I declare my js files in : 

public function hookDisplayHeader()

I'd like to add a condition like if($page_name == 'index')...

You see what I need. $page_name is a Smarty variable...How to get the same but for php?

Chris

Link to comment
Share on other sites

You don't say what version of Prestashop you need to support with this module, and PS v1.4 would likely work different than v1.5 or 1.6.  So I can give you some pointers to play with

 

You can try looking at the value of the controller

if (Tools::getValue('controller') == 'index')

Alternatively, you could check the value of 'PHP_SELF' which should be the full path to the PHP file.  Then apply comparison logic once you figure out what the path is

$_SERVER['PHP_SELF']
Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...

I have found a snippet in FrontController.php how to get page name

        if (!empty($this->page_name)) {
            $page_name = $this->page_name;
        } elseif (!empty($this->php_self)) {
            $page_name = $this->php_self;
        } elseif (Tools::getValue('fc') == 'module' && $module_name != '' && (Module::getInstanceByName($module_name) instanceof PaymentModule)) {
            $page_name = 'module-payment-submit';
        }
        // @retrocompatibility Are we in a module ?
        elseif (preg_match('#^'.preg_quote($this->context->shop->physical_uri, '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
            $page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
        } else {
            $page_name = Dispatcher::getInstance()->getController();
            $page_name = (preg_match('/^[0-9]/', $page_name) ? 'page_'.$page_name : $page_name);
        }
  • Like 2
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...