Jump to content

Can't fetch .tpl file from module with ajax


Recommended Posts

Hello everyone!
I'm new to prestashop. I'm trying to make a module that displays tabs with different content on one page. Ajax call is executed on document.ready() to get the content of first tab but i get an error "Missing template name" after $this->context->smarty->fetch(_PS_MODULE_DIR_.'mymodule/views/templates/front/mytemplate.tpl').
I spent the whole day trying to figure out what's wrong, but have no idea.
It works well when there's only html tags in the .tpl file, but when i place just {extends 'customer/page.tpl'}  or {extends "page.tpl'} - i get the error.


views/templates/identity.tpl

{extends 'customer/page.tpl'}

{block name='page_title'}
  {l s='Your personal information' d='Shop.Theme.Customeraccount'}
{/block}

{block name='page_content'}
  {render file='customer/_partials/customer-form.tpl' ui=$customer_form}
{/block}


It does insert template when macking just an ajax call from custom.js file but it inserts everything including header and footer etc. I would like to load only the content.

It's very simple but doesn't work. Please help!
Thanks in advance.

infowishes/infowishes.php

<?php

if (!defined('_PS_VERSION_'))
{
  exit;
}

class InfoWishes extends Module
{
    public function __construct()
    {
    $this->name = 'infowishes';
    $this->tab = 'front_office_features';
    $this->version = '1.0.0';
    $this->author = 'Roma Vavilov';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
    $this->bootstrap = true;

    parent::__construct();

    $this->displayName = $this->l('Information and Wishes');
    $this->description = $this->l('Displays customer information and wishes.');
    $link = new Link;
    $ajax_link = $link->getModuleLink('infowishes','ajax', array());

    Media::addJsDef(array(
        "ajax_link" => $ajax_link
    ));
    }
    
    public function install()
    {
      if (!parent::install() || !$this->registerHook('displayinfowishes') || !$this->registerHook('displayheader'))
        return false;
      return true;
    }
    public function uninstall()
    {
      if (!parent::uninstall() ||
        !Configuration::deleteByName('INFOWISHES')
      )
        return false;

      return true;
    }

    public function hookDisplayHeader()
    {
     $this->context->controller->addJS(($this->_path).'js/infowishes.js');
    }
    
    public function hookDisplayInfoWishes($params)
    {
     $this->context->smarty->assign(
     array(
     'my_module_name' => Configuration::get('INFOWISHES'),
     'my_module_link' => $this->context->link->getModuleLink('INFOWISHES', 'display')
     )
     );
     return $this->display(__FILE__, 'infowishes.tpl');
    }

}

controller/front/ajax.php

<?php
  require_once _PS_MODULE_DIR_.'infowishes/infowishes.php';

class InfoWishesAjaxModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {
		parent::initContent();
		$this->ajax = true;
    }
    	public function displayAjax()
	{
		echo Tools::jsonEncode($this->context->smarty->fetch(_PS_MODULE_DIR_.'infowishes/views/templates/front/identity.tpl'));;
		die();
	}

}

js/infowishes.js

  $( document ).ready(function() {
    AreqX();        
});
function AreqX(){
    jQuery.ajax({
        url: ajax_link,
        type: "POST",
        dataType: 'html',
success:function(data){
            console.log('seccess');
           $('#container').html(data);
        }
    });

error


SmartyException in smarty_internal_template.php line 678:
Missing template name
in smarty_internal_template.php line 678
at Smarty_Internal_Template->__get('source') in smarty_internal_compile_extends.php line 63
at Smarty_Internal_Compile_Extends->compile(array(array('file' => '$_smarty_tpl->tpl_vars['layout']->value')), object(Smarty_Internal_SmartyTemplateCompiler), array(), null, null) in smarty_internal_templatecompilerbase.php line 570
at Smarty_Internal_TemplateCompilerBase->callTagCompiler('extends', array(array('file' => '$_smarty_tpl->tpl_vars['layout']->value')), array()) in smarty_internal_templatecompilerbase.php line 349
at Smarty_Internal_TemplateCompilerBase->compileTag('extends', array(array('file' => '$_smarty_tpl->tpl_vars['layout']->value'))) in smarty_internal_templateparser.php line 3564
at Smarty_Internal_Templateparser->yy_r37() in smarty_internal_templateparser.php line 4392
at Smarty_Internal_Templateparser->yy_reduce('37') in smarty_internal_templateparser.php line 4493
at Smarty_Internal_Templateparser->doParse('3', '}') in smarty_internal_smartytemplatecompiler.php line 118
at Smarty_Internal_SmartyTemplateCompiler->doCompile('{** * 2007-2017 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License 3.0 (AFL-3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/AFL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <contact@prestashop.com> * @copyright 2007-2017 PrestaShop SA * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) * International Registered Trademark & Property of PrestaShop SA *} {extends file=$layout} {block name='content'} <section id="main"> {block name='page_header_container'} <header class="page-header"> {block name='page_header'} <h1>{block name='page_title'}{/block}</h1> {/block} </header> {/block} {block name='page_content_container'} <section id="content" class="page-content"> {block name='page_content'} <!-- Page content --> {/block} </section> {/block} {block name='page_footer_container'} <footer class="page-footer"> {block name='page_footer'} <!-- Footer content --> {/block} </footer> {/block} </section> {/block} ') in smarty_internal_templatecompilerbase.php line 283
at Smarty_Internal_TemplateCompilerBase->compileTemplate(object(SmartyDevTemplate)) in smarty_internal_template.php line 197
at Smarty_Internal_Template->compileTemplateSource() in smarty_internal_templatebase.php line 155
at Smarty_Internal_TemplateBase->fetch('C:\Users\roma\Documents\OSPanel\domains\localhost\prestadebug/themes/conic_account/templates/customer/wishes.tpl', null, null, object(SmartyDev), false, true, false) in SmartyDev.php line 41
at SmartyDev->fetch('C:\Users\roma\Documents\OSPanel\domains\localhost\prestadebug/themes/conic_account/templates/customer/wishes.tpl') in ajax.php line 29
at InfoWishesAjaxModuleFrontController->displayAjax() in Controller.php line 270
at ControllerCore->run() in Dispatcher.php line 428
at DispatcherCore->dispatch() in index.php line 28

 

Edited by vavilov2212 (see edit history)
Link to comment
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
×
×
  • Create New...