Jump to content

renderView() in Admin Module Controller not displaying


H4818

Recommended Posts

I have module with the following code which is not displaying in my back office:

 

module name: vendorprog

vendorprog/controllers/admin/AdminVendorController.php

<?php
if (!defined('_PS_VERSION_'))
	exit;

class AdminVendorController extends ModuleAdminController
{
	public function __construct()
	{
		ppp('__construct called');
		$this->display = 'view';
		parent::__construct();
		
	}
	
	public function initContent()
	{
		$this->renderView();
	}
	
	
	public function renderView()
	{
		ppp($this->getTemplatePath());
		
		$this->base_tpl_view = 'report.tpl';
		
		return parent::renderView();
	}
}

I have a file at /vendorprog/views/templates/admin/helpers/view/report.tpl

 

with the following code:

<p>Hello World</p>

I get the following error:

 

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'helpers/view/report.tpl''

 

How can I solve this? I still want to add functions that can be called through ajax. Please help

Link to comment
Share on other sites

  • 5 months later...
  • 3 months later...

Hi to every one, for your custom tpl file, can use the function

$this->context->smarty->createTemplate(<tpl_file_path>, $this->context->smarty);

The custom template file need to be in the directory of your module, in path views/templates/admin

 

Besta regards, Patrick T.

Link to comment
Share on other sites

If your module name is vendorprog , and the controller class name is AdminVendorController

then you set the base template name like this :

$this->base_tpl_view = 'report.tpl';

.

You should place the template file on :

../modules/vendorprog/views/templates/admin/vendor/helpers/view/report.tpl

 

.

BUT ... why you are using ppp() function which is an alias of dieObject() function within your controller __contruct() and renderView() method ?

ppp('__construct called');// will print: __construct called

ppp($this->getTemplatePath());// will print simliar to: /modules/vendorprog/views/templates/admin/

.

And according to your AdminVendorController.php file, the following code won't display the content of your report.tpl file

return parent::renderView();
Link to comment
Share on other sites

  • 9 months later...

Hi, 

 I'm trying to create tab under dashboard. I was able to get name of the tab. But I'm facing problem when trying to renderView. Below code is for Controller

<?php
 class AdminHomePageController extends ModuleAdminController{
  public function __construct(){
  $this->table = 'homepage_tab';
  $this->className = 'AdminHomePage';
  $this->module = 'homepage';
  $this->fiels_list = array(
  'id' => array('title' => $this->l('id'), 'align' => 'center', 'width'=>25),
  'title' => array('title' => $this->l('Title'), 'align' => 'center', 'width' => 25),
  'image_path' => array('title' => $this->l('Image Path'), 'align' => 'center', 'width' => 25),
  'assoc_link' => array('title' => $this->l('Associated Link'), 'align' => 'center', 'width' => 25),
  'date_add' => array('title' => $this->l('Date Added'), 'align' => 'center', 'width' => 25),
  );
  $this->bootstrap = true;
  parent::__construct();
  $this->meta_title = $this->l('Webservice Settings');
  $this->toolbar_title[] = $this->meta_title;
  }
public function initContent(){
$this->renderView();
}


  public function renderView(){
  $tpl = $this->context->smarty->createTemplate(dirname(__FILE__).'../../views/templates/admin/displayAdminProductsExtra.tpl');
  return $tpl->fetch();
  }
 }

Below is .tpl code

<h3 class="page-product-heading">AdminTab</h3><div class="rte">
<form action="" method="post" id="comment-form">
<div class="form-group">
<label for="title">Title:</label>
<input type="text" name="title" id="title" class="form-control">
</div>
<div class="form-group">
<label for="image">Image Path:</label>
<input type="text" name="image" id="image" class="form-control">
</div>
<div class="form-group">
<label for="assoc_link">Associated Link:</label>
<input type="text" name="assoc_link" id="assoc_link" class="form-control">
</div>
<div class="panel-footer">
<a href="{$link->getAdminLink('AdminProducts')}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a>
<button type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save'}</button>
<button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save and stay'}</button>
</div>
</form>
</div>

Can any one please help to display the content of tpl?

Error that I'm getting is Uncaught --> Smarty: Unable to load template file

I need to fetch the table from db and display it that tab which comes under dashboard. Any help would be great. Thanks in advance. 

Link to comment
Share on other sites

  • 2 months later...

Hi, 


 


I am a presta newbie and I have a similar problem, I created a custom module with custom controller, then  under Administration->Menus I created a new admin menu with the new module and controller. After that I created a test template file under "modules/szilveszterfirst/views/templates/admin/szilveszter_first/helpers/view/test.tpl". Everything works fine, except the renderView function, the template file is loaded(I printed out the result), but in the admin page doesn't show anything. Is there any prerequisite, that I didn't do? e.g. the template should contain something special(actually contains a few html tags for test sake)?



class AdminSzilveszterFirstController extends ModuleAdminController {

public function __construct() {
$this->lang = false;
parent::__construct();
}

public function initContent(){
$this-> renderView();
return parent::initContent();
}
public function renderView() {
$this->base_tpl_view = 'test.tpl';
//printf("<pre>%s</pre>",print_r(parent::renderView(),true));
return parent::renderView();
}
}
Link to comment
Share on other sites

  • 7 months later...
  • 2 months later...

Hi guys,

 

I have basically the same code than VinayC :

class AdminPillowGeneratorFabricController extends ModuleAdminController
{
	public function __construct()
	{
                $this->className = 'PillowGeneratorFabric';	// Model class name
		$this->table = 'pillowgenerator_fabric';	// Table in database (without prefix)

		// Using view list helper
		$this->fields_list = array(
			'id_pillowgenerator_fabric' => array(
				'title' => $this->l('ID'),
				'align' => 'center',
				'width' => 25),
			'name' => array(
				'title' => $this->l('Name'),
				'align' => 'center',
				'width' => 100),
                        ),
		);

		$this->bootstrap = true;
		
		parent::__construct();
        }

	public function renderView() 
	{
		$tpl = $this->context->smarty->createTemplate(_PS_MODULE_DIR_.'/pillowgenerator/views/templates/admin/fabric_view.tpl');
                return $tpl->fetch();
        }
}

But the View button give me this error :

 

Fatal error: Class 'PillowGeneratorFabric' not found in /var/www/html/classes/controller/AdminController.php on line 1617

 

As far as I search nobody found a clear solution to this problem. Any news ?

Edited by plup (see edit history)
  • Thanks 1
Link to comment
Share on other sites

  • 3 years later...

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
×
×
  • Create New...