Jump to content

[SOLVED] {$tpl_dir} shows different url (as root server) ...


Recommended Posts

Hello!

 

I want to use {$tpl_dir} in template files to show some images in new folder which is in the template directory (not the "imgs" folder).

 

When I use {$css_dir} and {$img_dir}, it works without problems but for the {$tpl_dir},
that is not correct url.
It shows the url as "domain's name/root path to server/themes/themesname/... "

 

I found several same questions in this forum but no solution...

Is there someone who know good solution?

Edited by tatamimi (see edit history)
Link to comment
Share on other sites

Prestashop does not actually add the template URL path to the smarty engine, so you would need to add this yourself in the FrontController class

 

If you search the FrontController for 'css_dir' you will find a block of code like below

        $assign_array = array(
            'img_ps_dir' => _PS_IMG_,
            'img_cat_dir' => _THEME_CAT_DIR_,
            'img_lang_dir' => _THEME_LANG_DIR_,
            'img_prod_dir' => _THEME_PROD_DIR_,
            'img_manu_dir' => _THEME_MANU_DIR_,
            'img_sup_dir' => _THEME_SUP_DIR_,
            'img_ship_dir' => _THEME_SHIP_DIR_,
            'img_store_dir' => _THEME_STORE_DIR_,
            'img_col_dir' => _THEME_COL_DIR_,
            'img_dir' => _THEME_IMG_DIR_,
            'css_dir' => _THEME_CSS_DIR_,
            'js_dir' => _THEME_JS_DIR_,
            'pic_dir' => _THEME_PROD_PIC_DIR_
        );

You need to revise that to include your path, like 'my_tpl_dir'.  Then in your .tpl file you can use {$my_tpl_dir}
 

        $assign_array = array(
            'img_ps_dir' => _PS_IMG_,
            'img_cat_dir' => _THEME_CAT_DIR_,
            'img_lang_dir' => _THEME_LANG_DIR_,
            'img_prod_dir' => _THEME_PROD_DIR_,
            'img_manu_dir' => _THEME_MANU_DIR_,
            'img_sup_dir' => _THEME_SUP_DIR_,
            'img_ship_dir' => _THEME_SHIP_DIR_,
            'img_store_dir' => _THEME_STORE_DIR_,
            'img_col_dir' => _THEME_COL_DIR_,
            'img_dir' => _THEME_IMG_DIR_,
            'css_dir' => _THEME_CSS_DIR_,
            'js_dir' => _THEME_JS_DIR_,
            'pic_dir' => _THEME_PROD_PIC_DIR_,
            'my_tpl_dir' => _THEME_DIR_,
        );

And the proper way to do this is to create an override of the FrontController class, and implement your own init() function like below

    public function init()
    {
        parent::init();
        $this->context->smarty->assign('my_tpl_dir', _THEME_DIR_);
    }
  • Like 1
Link to comment
Share on other sites

Thank you so much for your quick reply bellini13!

 

I added this code

'my_tpl_dir' => _THEME_DIR_,

in "classes/controller/FrontController.php" file, and it works perfectly!

But I don't understand which file to put the code for init() function...

Is this the same file (FrontController.php)?

Link to comment
Share on other sites

Thank you again bellini13!

I shouldn't change the core file... OK now I understand...

 

I modified the core file to the original.

I copied the "classes/controller/FrontController.php" file,

and added

$this->context->smarty->assign('my_tpl_dir', _THEME_DIR_);

after

public function init()
	{

	 ------------ other codes --------

		parent::init()

and put it in "override/classes/controller/" folder and deleted cash file.

 

It works perfectly!

 

Thank you a lot again.

Link to comment
Share on other sites

Thank you vekia.

 

... There is also the way like that ...

 

I didn't want to put my image files in "imgs" because there are already many files.

but that is also possible to make new folder in the "imgs" and separate from other files...

Link to comment
Share on other sites

×
×
  • Create New...