Jump to content

Prestashop custom module tpl getting html encoded


Recommended Posts

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.

image.png.5b7e12420bf2c4a9b5d333438ca49c54.png

Here is the relevant php code

<?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');
    }
}

 

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...