Passing variable value from module file to template file

Open to all! Ask other shopowners for help.
Post Reply
Moxamint
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 times

Passing variable value from module file to template file

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Passing variable value from module file to template file

Post by raiwa »

Just move the query to the main file. The variable should be available then in the template file without any additional coding.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
Moxamint
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 times

Re: Passing variable value from module file to template file

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


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply