Page 1 of 1

Passing variable value from module file to template file

Posted: Thu Oct 05, 2023 2:39 am
by Moxamint
Hi,

I wanted to add "Order Status" to the order notification email. I achieved that by using the following SQL query in the template file <<tpl_n_checkout.php>>:

Code: Select all

    $q = $GLOBALS['db']->query( "SELECT orders_status_name FROM orders_status INNER JOIN orders ON orders_status.orders_status_id = orders.orders_status WHERE orders.orders_id = {$order->get_id()};" );
    $statuses = $q->fetch_assoc();

    foreach ($statuses as $status) {
        $order_status = $status;
    }
I think making the SQL query in the template file is not the right thing to do. But how do I do the query in the main module file <<n_checkout.php>> and then pass the value of $order_status to the template file?

Any assistance would be highly appreciated.

Phoenix = v1.0.8.20
PHP = 7.4

Thanks, Eddy

Re: Passing variable value from module file to template file

Posted: Thu Oct 05, 2023 4:37 am
by raiwa
Just move the query to the main file. The variable should be available then in the template file without any additional coding.

Re: Passing variable value from module file to template file

Posted: Thu Oct 05, 2023 5:05 am
by Moxamint
raiwa wrote: Thu Oct 05, 2023 4:37 am Just move the query to the main file. The variable should be available then in the template file without any additional coding.
Thank you! My attempt to execute the query in the main file failed because I put the query AFTER template file was loaded. Now it's working perfectly.