How to load a template file from my admin controller in custom module in prestashop

How to load a template file from my admin controller in custom module in prestashop

How to load a template file from my admin controller in custom module in prestashop 1.6

if (!defined('_PS_VERSION_')) exit;
 class QueryAllTrxController extends ModuleAdminController
{

public $module;
public function __construct()
{
parent::__construct();
}

public function initContent()
{
parent::initContent();
$this->setTemplate('display.tpl');
//$this->setTemplate(_PS_THEME_DIR_.'mypage.tpl');
}    

}

I had the same problem and it took forever to figure out. I ended up spotting the solution in this video : https://www.youtube.com/watch?v=CdnJpLqqvcM

Any this is how I got it to work :

1 - Create the controller in ModuleName/controllers/AdminMyControllerNameController.php

class AdminMyControllerNameController extends ModuleAdminController
{

public function __construct()
{
    $this->display = 'view';
    $this->meta_title = $this->l('metatitle');
    $this->toolbar_title = $this->l('tollbartitle');
    parent::__construct();
}

public function initContent()
{
    $this->show_toolbar = true;
    $this->display = 'view';
    $this->meta_title = $this->l('META TITLE');

    parent::initContent();

    $this->setTemplate('templatename.tpl');


}

public function initToolBarTitle()
{
    $this->toolbar_title = $this->l('TOOLBAR TITLE??');
}

public function initToolBar()
{
    return true;
}

}

2 - Create the template file in ModuleName/views/admin/my_controller_name/template.tpl

You have to create a directory in the views/admin folder using the name of your controller written with underscores and no caps.

Anyway I hope this will help.

create a custom controller back office on Custom module in , Once included in module main file you can create an instance of you class To assign variable that you can use on template there is $this->context->smarty->​assig() function. contollers/admin/Checkstatus.php'; class MyModule extends Prestashop Controller in your module you have to put the override  Create Admin module controllers 1.7.5. Since 1.7.3 you create and override templates and services in your modules. Since 1.7.4, you can create and override forms and console commands. Since 1.7.5, you can create your own “modern” controllers! Starting on PrestaShop 1.7.5, you can rely on the modern environment to add new entry points


The code $this->setTemplate('display.tpl'); is loading a template file modules/your-custom-module/views/templates/admin/display.tpl or modules/your-custom-module/display.tpl.

Load Tpl from Custom Backoffice Menu - Core , Why is it not searching the file at module/view/templates/admin? My Admin Controller is: class AdminDypRefundController extends  For example, we use a default Helper to generate forms in the admin panel and we need to generate a custom input which cannot be implemented by using default Prestashop templates. Partner With Us Let's discuss how to grow your business.


The classname must be named that way: AdminQueryAllTrxController

you can put display.tpl in :

modules\module_name\views\templates\admin\classe_name(QueryAllTrx)

and use :$this->setTemplate('display.tpl'); in your AdminQueryAllTrxController

How to create custom views for a module's backend controller , PrestaShop Forums. Existing user? Sign In Second thing I need is to show a custom tpl file for this controller. "Unable to load template file themes/​yourtheme/modules/yourmodule/views/templates/admin/yourtpl.tpl return the $​page in your renderView, renderForm or any method that you use. In PrestaShop 1.4, the module's template files were to be placed at the root of the module's folder. For compatibility reasons, template files can still reside in the root folder in PrestaShop 1.5, although the sub-folders of /views/templates/ are now the recommended locations.


First of all add controller to your module:

modules\module_name\controllers\admin\SomeNameController.php

and extend it by ModuleAdminController, you need at least two methods for it to work properly __construct and initContent put the following code to the later method:

$this->content .= $this->context->smarty->fetch($this->pathToTpl);

            $this->context->smarty->assign(array(
                'content' => $this->content,
            ));

You could replace $this->pathToTpl with any path which is pointed to your tpl file, I'm prefer to create the path dynamically. You can see a simple example here:

class SomeNameController extends ModuleAdminController{
  var $pathToTpl;
  public function __construct()
    {
        $this->bootstrap = true;
        $this->context = Context::getContext();

        $this->pathToTpl = _PS_MODULE_DIR_ .
            $this->module->name .  // put the name of module
            '/views/templates/admin' .
            '/' .
            'templateName.tpl';
        parent::__construct();
    }

  public function initContent()
    {
        parent::initContent();

        $this->content .= $this->context->smarty->fetch($this->pathToTpl);

        $this->context->smarty->assign(array(
            'content' => $this->content,
        ));

    }

}

finally you need to place templateName.tpl in the path you wanted to be:

modules\module_name\views\templates\admin\templateName.tpl

renderView() in Admin Module Controller not displaying, vendorprog/controllers/admin/AdminVendorController.php 'SmartyException' with message 'Unable to load template file 'helpers/view/report.tpl'' The custom template file need to be in the directory of your module, in path  If the module needs to work with PrestaShop 1.4, the template files should be placed either directly at at the root of the module's folder, or in a /template folder at the root of the module's folder. /views/templates/admin. Sub-folder for template files used by the module's administration controllers.


Displaying content on the front office :: PrestaShop Developer , Creating your own symfony controller tests · Creating your own web acceptance tests · Creating your own Behat tests Save your file, and already you can hook your module's template into the /views/templates/admin/ : back office features. with a minimal content, and put it in: modules/yourmodule/​controllers/front/. The controller class is called ProductControllerCore. You will need to create a PHP file and place it either of the override folders of a module. Indeed, since PrestaShop 1.5, these files can be stored within a module and their management will follow it. Overriding a class does not mean to copy paste the whole file content.


How to create full custom page 1.7 - Addons, modules , I will probably include file page.tpl and put my content in page_content block. I found some tutorials and start by creating a new module : I I have created about.php file in this path : modules/xav/controllers/front/about.php You can create a CMS page with any HTML content from the admin panel  Base project example, which uses this admin module for multilanguage content and dashboard: yii2-template-multilanguage. Base project example, which uses this admin module for simple data: yii2-template-simple. Addition module description you can see in my Personal site. 2 Dependencies. php >= 7.1; composer; MySql >= 5.5; 3 Installation. Via composer:


How to create a custom page in admin panel?, I tried using creating a new admin controller file and in that set the template path and i created a menu using admin panel and there i mentioned the controller class name for Of course leave out the module part if you don't use one file this way) put the tpl file in your admin/theme/controllername folder. One method for an administrator to add such extensions to the GPO is by adding new settings to the Administrative Templates sections. This can be done by adding .ADM files to the existing