Jump to content

Fatal error: Uncaught -> Smarty: Unable to load template file '/index.tpl'


estebannerja

Recommended Posts

I have this error in prestashop 1.7.0.6 when changing language on the front:

 

Fatal error: Uncaught -> Smarty: Unable to load template file '/index.tpl' <- thrown in /var/www/vhosts/modajdej.com/httpdocs/modajdej/vendor/prestashop/smarty/sysplugins/smarty_internal_templatebase. Php on line 129

 

Can somebody help me?

Thank you so much!

Link to comment
Share on other sites

  • 5 months later...
  • 1 month later...

I have a solution that will help you while it is not clear what causes this. 

 

The fact is that the loaded template should be index.tpl and not /index.tpl. Somehow Prestashop is adding a / before the template name, but I do not know how that happens yet, since I had no time to look into it more deeply.

 

To solve this problem and get your store running again, open the following file:

 

/home2/casav287/public_html/novo/classes/controller/FrontController.php

 

At line 649, you are going to find this function :

protected function smartyOutputContent($content)
    {
        $this->context->cookie->write();

        $html = '';

        if (is_array($content)) {
            foreach ($content as $tpl) {
                $html .= $this->context->smarty->fetch($tpl, null, $this->getLayout());
            }
        } else {
            $html = $this->context->smarty->fetch($content, null, $this->getLayout());
        }

        Hook::exec('actionOutputHTMLBefore',  array('html' => &$html));
        echo trim($html);
    }

Now we will made a small change at line 660. The function will be like this now:

protected function smartyOutputContent($content)
    {
        $this->context->cookie->write();

        $html = '';

        if (is_array($content)) {
            foreach ($content as $tpl) {
                $html .= $this->context->smarty->fetch($tpl, null, $this->getLayout());
            }
        } else {
             if(substr($content, 0, 1) == '/')
               $content = substr($content, 1);

            $html = $this->context->smarty->fetch($content, null, $this->getLayout());
        }

        Hook::exec('actionOutputHTMLBefore',  array('html' => &$html));
        echo trim($html);
    }

This code will remove the / from the template name.

 

Save it and everything will be ok. When I have more time I will update this thread with the real solution.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

I know this is an old post however I found an explanation that won't require to change Prestashop code, as suggested by @andresams.

First, @andresams' solution is not the best as:

  • If you modify the framework's code, any update will break it and you will have your bugs back
  • The solution is not solving the actual problem (see below)

If you dig deeper you will find that the template being rendered is found through TemplateFinderCore::getTemplate(...):

// file: classes/Smarty/TemplateFinder.php
// class: TemplateFinderCore

55  foreach ($templates as $tpl) {
56      if (is_file($dir.$locale.DIRECTORY_SEPARATOR.$tpl.$this->extension)) {
57          return $locale.DIRECTORY_SEPARATOR.$tpl.$this->extension;
58      }
59      if (is_file($dir.$tpl.$this->extension)) {
60          return $tpl.$this->extension;
61      }
62      if (is_file($dir.$tpl) && false !== strpos($tpl, $this->extension)) {
63          return $tpl;
64      }
65  }

Please note that I am working with Prestashop v1.7.

Problem is on l.57: if $locale is null then l.56 and l.59 checks become identical, however l.57 will add a leading "/" to the returned template name -as $locale is null-.

The problem for me was that I thought I correctly added a language, manually, when actually it did not work properly. Therefore, the locale was not recognised and, instead of throwing an error or fallbacking to the default locale, it just assumed the locale was null.

So if you want to add a new language, do NOT do:

  • International > Localisation > Languages > (+)

but instead, DO:

  • International > Translations > Add / Edit a language
  • Then you will see it appear in International > Localisation > Languages

Please find more detailed information and screenshots about how to do that here: https://belvg.com/blog/how-to-add-a-language-in-prestashop-1-7.html

Cheers,

Will

Edited by will (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 10 months later...
  • 3 months later...
19 hours ago, robiul5064 said:

Fatal error: Uncaught --> Smarty: Unable to load template file 'menu_box.tpl' in 'footer.tpl' <-- thrown in /home/bestmoni/public_html/inc/libs/smarty3/sysplugins/smarty_internal_template.php on line 219

Disable the "menu_box" module...

Best regards

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