Jump to content

Problem including file in module


jackads
 Share

Recommended Posts

Hi people,

 

I'm new im PrestaShop and in Web Development (PHP), but I already playing with PrestaShop a little...

 

I have a doubt about a thing, I tried to include a file in my module, but it shows a weird error.

 

When I include a file in my module like this:

 

include "file.php";

 

It works in the PrestaShop page, but it broke the Module Management (back office) page.

 

When I include a file like this:

 

include "../file.php";

 

This time it works in the back office in Modules page, but now the PrestaShop page broke.

 

If I include in the two ways:

 

include "file.php";
include "../file.php";

 

Now the two pages works, but it always will show a error message in the header.

 

It's very weird the fact that when a page works another broke, and I cant release a module who will always show a error message to the user, even it working.

 

 

God bless, thanks for all!

Share this post


Link to post
Share on other sites

  • 2 years later...
For this to work, your directory structure should be (Using PrestaShop 1.6):

 

    -- mymodule.php

    -- views

    ---- templates

    ------ hook

    ------ displayFooBarTemplate.tpl

    -------- inc

    ---------- foo.tpl

    ---------- bar.tpl

 

**Absolute way:**

 

From your main module file:

 

    protected function displayFooBarTemplate()

    {

        global $smarty;

 

        ...

 

        $smarty->assign('module_templates', dirname(__FILE__).'/views/templates/');

 

        return $this->display(__FILE__, 'displayFooBarTemplate.tpl');

    }

 

then in your tpl file (displayFooBarTemplate.tpl):

 

    {include file="{$module_templates}hook/inc/modal/foo.tpl"}

    

    {include file="{$module_templates}hook/inc/modal/bar.tpl"}

 

**Relative way (my favorite):**

 

    {include './inc/foo.tpl'}

    

    {include './inc/modal/bar.tpl'}

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

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