Prestashop PHP Include in .tpl not working

I am creating a storefront for a client using Prestashop. Prestashop uses Smarty.TPL files. I read flexible documentation and browsed the web, but all suggestions do not work.

First, I created the site using regular .php pages, and I include the .php header on each page.

Then I created a directory for prestashop and got it. I edited the header.tpl file and was able to execute hard code in the header.php code. The problem with this; when I want to edit the title (nav bar, images, social media), I have to edit it in two different places. So I tried to "Include" my header.php file.

Although, when I try to use smarty {include_PHP "file.php"} and / or {PHP} enable ... {PHP}, Prestashop errors and gives me a blank white page - no errors were generated - (in chrome it gives me an "error server ") until I select the inbox.

I tried replacing all header.tpl code with smarty enabled and another piece of code that had a header, but none of them worked. Any suggestions? I just want one heading where I only need to edit it once to make changes.

Using Prestashop v 1.4.4.0

Edit: I changed allow_php to true from false. Now he is trying to add the file, although he says that he cannot find the file. I placed it next to header.tpl and just used:

{php} include('navBar.php'); {/php} 
+4
source share
2 answers

ANSWERED!

When using Smarty.TPL files, when you include something, you do not include the path to the file you are working on. You indicate where the index is from.

Example:

I am working on header.tpl, this is located at: site root / smartyinstall / themes / THEMENAME / header.tpl

When a search object searches for a file, it actually searches for it in the smarty root folder, because the header.tpl header is pulled out to the index.html page, which is located in the smartyinstall folder.

So you need to go from there. In my case, the title I was trying to include was in: site root / includes / navBar.php

so I had to write include ('../includes/navBar.php') ;, and only up one directory instead of four.

I hope this helps everyone who has such a problem!

+4
source

It was considered very bad practice to include php in smart.tpl files, so I highly recommend that you not add code in this way. One of the main reasons for disabling the {php} tag is to prevent code injection attacks. E-commerce sites are inherently natural targets for exploits.

A better approach would be to override the FrontController class to assign your custom code to smarty - this could then be inserted into header.tpl without resorting to using php include() .

With the class and controller overrides available in Prestashop 1.4.x, there is no real reason why you should resort to hacks and / or modifications to the main distribution.

Floor

0
source

All Articles