Jump to content
estebannerja

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

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

Hi will, 

Thanks Will with this post you gave me an idea of my problem and I managed to solve it. Everything happened because of a migration I made from 1.6 to 1.7 and I made it manual and I forgot to copy the translation folder.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More