0
votes

I am a beginner and I am learning how to create a front-office controller. I have written the following code but shows nothing when I load the page. I haven't given any reference to it in my module code yet. How should I proceed?

<?php

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

class AbcMyPageModuleFrontController extends ModuleFrontController
{
  public function initContent()
{
    parent::initContent();
    $this->setTemplate('module:abc/views/templates/front/myFirst.tpl');
}
}
1

1 Answers

0
votes

Your path to your file seems wrong, here is a simple version for your eyes only :

<?php

// Edit name and class according to your files, keep camelcase for class name.
require_once _PS_MODULE_DIR_.'modulename/modulename.php';

class ModuleNameAjaxModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {

        $module = new ModuleName;

        // Usefull vars derivated from getContext
        $context = Context::getContext();
        $cart = $context->cart;
        $cookie = $context->cookie;
        $customer = $context->customer;
        $id_lang = $cookie->id_lang;


        // Template path : modules/modulename/views/template/front/template.tpl
        // Just put some vars in your template
        $this->context->smarty->assign(array('myvar'=>'thevalue'));
        $this->setTemplate('template.tpl');

    }
}