Jump to content

How to: Include file in smarty template


cingkonext

Recommended Posts

I made a hook header function as below:

public function hookHeader ($ params)
    {
        if ($ this-> isModuleAvailable ())
            return;
        $ This-> context-> controller-> addCSS (($ this-> _path). 'Mystyle.css', 'all');
        $ This-> context-> controller-> addJS (($ this-> _path). 'Myjavascript.js');
    }

If the variable in the function does not work (like the mobile version), how to include these two files on my smarty page (Mypage.tpl)?

so far I've made it like this (in file "Mypage.tpl"):

{If ($ mobile) == '1 '}
    <script type="text/javascript" src="{$new_base_dir}Myjavascript.js"> </ script>
{/ If}

This works well to call the javascript functions. but how to include files mystyle.css?

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

My Hook footer:

public function hookFooter($params)
    {
        require_once(_PS_TOOL_DIR_.'mobile_Detect/Mobile_Detect.php');
        $this->mobile_detect = new Mobile_Detect();
        $mobile = '0';
        if ($this->mobile_detect->isMobile())
        {
            $mobile = '1';
        }
      
        $protocol = (Configuration::get('PS_SSL_ENABLED') || (!empty($_SERVER['HTTPS'])
            && strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
        
        $endURL = __PS_BASE_URI__.'modules/mymodule/';
    
        if (method_exists('Tools', 'getShopDomainSsl'))
            $moduleURL = $protocol.Tools::getShopDomainSsl().$endURL;
        else
            $moduleURL = $protocol.$_SERVER['HTTP_HOST'].$endURL;
      
        $this->smarty->assign(array(
            'mobile' => $mobile,
            'new_base_dir' => $moduleURL,
        ));
        return $this->smarty->fetch($this->template_directory.'Mypage.tpl');
    }

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...