Prestashop PHP Include in a .tpl does not work
NickName:ntgCleaner Ask DateTime:2011-09-02T00:47:48

Prestashop PHP Include in a .tpl does not work

I am creating a storefront for a client using Prestashop. Prestashop uses Smarty .TPL files. I read through smarty documentation and scoured the web but all of the suggestions are not working.

I first made a site using regular .php pages and I am including the header.php on every page.

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

Though, when I try using smarty's {include_PHP "file.php"} and/or {PHP}include...{PHP}, Prestashop errors out and gives me a blank white page - no errors are given - (in chrome it gives me a "server error") until I take out the includes.

I tried replacing the entire header.tpl code with a smarty include and another piece of code that had a header hook, but none of these worked. Any suggestions? I just want one header where I only have to edit it once to make changes.

Using Prestashop v 1.4.4.0

Edit: I changed allow_php to true from false. Now it's trying to add the file, though it says it can't find the file. I placed it next to header.tpl and just used:

{php}
            include('navBar.php'); 
       {/php} 

Copyright Notice:Content Author:「ntgCleaner」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7273602/prestashop-php-include-in-a-tpl-does-not-work

Answers
ntgCleaner 2011-09-02T00:56:59

ANSWERED!\n\nWhen using Smarty .TPL files, when you include something, you are not including from the path of the file you are working on. You are including from where the index is.\n\nExample:\n\nI am working on header.tpl, this is located in:\nsiteroot/smartyinstall/themes/themename/header.tpl\n\nWhen the include is looking for the file, it is actually looking for it in the smarty root folder because the header.tpl is being pulled into the index.html page that is in the smartyinstall folder. \n\nSo, you have to go from there. In my case, the header that I was trying to include was in:\nsiteroot/includes/navBar.php\n\nso, I had to write include('../includes/navBar.php');, only going up one directory, instead of four.\n\nI hope this helps everyone that has a problem like this!",


More about “Prestashop PHP Include in a .tpl does not work” related questions

Prestashop PHP Include in a .tpl does not work

I am creating a storefront for a client using Prestashop. Prestashop uses Smarty .TPL files. I read through smarty documentation and scoured the web but all of the suggestions are not working. I f...

Show Detail

Include other .tpl in a .tpl file Prestashop

I'm usinh a Prestashop 1.5.4.1, and I would like to call a module in other module (precisely I need to use slider module just above the home featured products). I tried to call it via include file...

Show Detail

Include PHP File in Smarty tpl

I want to include a PHP script that outputs some HTML in productdetail-full.tpl file (Smarty / Prestashop 1.6.x) I tried: {php} include('show-stock-pos.php'); {/php} AND {include_php 'show-...

Show Detail

How to detect device in smarty in prestashop 1.7 in a TPL file?

I want the following: & I understand I have to take the codes from context.php of PrestaShop but I seem to be making an error. A link to getcontext is as follows: (The code to detect mobile de...

Show Detail

How to inspect html code in Prestashop to link to the PHP TPL files

It is my understanding (prob completely wrong) that the php/tpl/etc files of a Prestashop site create the html page(s) of my website (see image). Im using Developer tools on Firefox Quantum Dev ed...

Show Detail

prestashop 1.7.5 show product-discounts.tpl into miniatures/product.tpl

i have problems when i try to show product discounts into the miniatures of search results. I'm using prestashop 1.7.5.1 version and php 7.0 in templates/catalog/product.tpl y have the followin co...

Show Detail

javascript code with php into .tpl prestashop

I'm trying to do a conditional selector with javascript and php. I have already done before, but in wordpress (pure php), now I have to adapt to prestashop (.tpl file). It is not so easy to write ...

Show Detail

Display function in header.tpl - Prestashop

I would like to say that i am quite new to prestashop. I have added FrontController.php to override/classes/controller. The file contains the following code class FrontControllerCore extends Cont...

Show Detail

PHP Prestashop extend form.tpl

I would like to extend the form.tpl of Prestashop (1.6.1.1). Therefor I created the following path in my module folder: modules/mymodule/views/templates/admin/export/helpers/form/form.tpl and

Show Detail

Display content with display.php and display.tpl in PrestaShop

I read http://doc.prestashop.com/display/PS16/Displaying+content+on+the+front+office and I try to create a display.php file and a display.tpl file. But I don't realize for sure where they must be ...

Show Detail