Prestashop custom module tpl getting html encoded

45 Views Asked by At

I have created my first custom prestashop(v8) module. For some reason the tpl file is getting html encoded in the website frontend. I inspected the site code and noticed the tpl file content is getting added to the site as follow

    <div class="product-additional-info">
    &lt;label for=&quot;custom_instructions&quot;&gt;Custom Instructions&lt;/label&gt;
&lt;textarea id=&quot;custom_instructions&quot; name=&quot;custom_instructions&quot; rows=&quot;4&quot; cols=&quot;50&quot;&gt;&lt;/textarea&gt;

</div>

You see how <label became &lt;label the corresponding tpl file for this looks like this

<label for="custom_instructions">{l s='Custom Instructions'}</label>
<textarea id="custom_instructions" name="custom_instructions" rows="4" cols="50"></textarea>

Do you have any ideas or suggestions as to why this is happening? Please check the screenshot of how it looks on the site frontend because of the html encoding.

enter image description here

Here is the relevant php code as requested

<?php
class custominstructions extends Module {
    public function __construct() {
        $this->name = 'custominstructions';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Sayantan Roy';
        $this->need_instance = 0;
        $this->bootstrap = true;
        parent::__construct();

        $this->displayName = $this->l('Custom Instructions');
        $this->description = $this->l('Add a text box for custom instructions on the product page.');

        // Set the module's bootstrap status to true
        $this->bootstrap = true;
    }

    public function install() {
        if (!parent::install() || !$this->registerHook('displayProductAdditionalInfo') || !$this->registerHook('actionValidateOrder') || !$this->registerHook('displayAdminOrder')) {
            return false;
        }
        return true;
    }

    public function uninstall() {
        if (!parent::uninstall()) {
            return false;
        }
        return true;
    }

    public function hookDisplayProductAdditionalInfo($params) {
        $this->context->smarty->assign(array(
            'custom_instructions' => $this->display(__FILE__, 'views/templates/hook/custom_instructions.tpl'),
        ));

        return $this->display(__FILE__, 'views/templates/hook/product_additional_info.tpl');
    }

    public function hookActionValidateOrder($params) {
        $order = $params['order'];
        $customInstructions = Tools::getValue('custom_instructions');
        if (!empty($customInstructions)) {
            // Save the custom instructions to the order
            Db::getInstance()->insert('order_message', array(
                'id_order' => (int)$order->id,
                'message' => pSQL($customInstructions),
            ));
        }
    }

    public function hookDisplayAdminOrder($params) {
        $orderId = (int)Tools::getValue('id_order');
        $orderMessages = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'order_message` WHERE `id_order` = '.$orderId);
        $this->context->smarty->assign(array(
            'orderMessages' => $orderMessages,
        ));

        return $this->display(__FILE__, 'views/templates/admin/custom_instructions_order.tpl');
    }
}
0

There are 0 best solutions below