Jump to content

SmartyException: Unable to load template file


johnmark

Recommended Posts

PS version 1.6.0.8

Get "Unable to load template file" in Controller (i.e. AdminMTestConroller) for following code.

 

class AdminMTestController extends ModuleAdminController
{
..
    public function renderView()
    {
        if (version_compare(_PS_VERSION_, '1.5.6.0', '>'))
        $this->base_tpl_view = 'view_bt.tpl'  ;
         return parent::renderView();
     }

.....}

 

After several hours tracing, finally, the problem laid in classes\Tools.php

 
public static function toUnderscoreCase($string)
{
// 'CMSCategories' => 'cms_categories'
// 'RangePrice' => 'range_price'
 return Tools::strtolower(trim(preg_replace('/([A-Z][a-z])/', '_$1', $string), '_'));
}
 
It set the tpl_folder to "m_test" and resulting in customize template not found.
 
Suggest to change it to 
public static function toUnderscoreCase($string)
{
// 'CMSCategories' => 'cms_categories'
// 'RangePrice' => 'range_price'
     preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $string, $matches);

     $ret = $matches[0];

     foreach ($ret as &$match) {
         $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
     }
    return implode('_', $ret);
}
 
 
Hope it help others!

 

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