SeanP Posted February 1, 2021 Share Posted February 1, 2021 I was trying to convert some PHP I have in {php} tags in templates to hooks. However, I need do a DB query for each service in the clientareaproducts.tpl within the following for loop: {foreach key=num item=service from=$services} How to I query each service, then use the template variables in the template? I am fine with keeping the {php} tag in the template for this (I am the designer and developer of my site), but I get an error trying to use PDO in the {php} tags ("ParseError: syntax error, unexpected 'use' (T_USE)": use WHMCS\Database\Capsule; // Get PDO for the database queries $pdo = Capsule::connection()->getPdo(); How to I either use PDO in the {php} tag or move this to a hook and still be able to do a DB query for each service? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 2, 2021 Share Posted February 2, 2021 14 hours ago, SeanP said: How to I query each service, then use the template variables in the template? perhaps the hook in the thread below will give you a starting point - it loops through the $services array; queries the database for a dedicated IP value; adds it back to the array and returns the updated array back to the template. 14 hours ago, SeanP said: I am fine with keeping the {php} tag in the template for this don't be - at some point, it really will be deprecated and if your php knowledge is good enough for use in tags, it should be good enough for hooks. ... and depending on what you're wanting to do, you might not even need to use capsule to query the database.... you might be able to get the info using the class docs or from other existing template variables. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted February 2, 2021 Author Share Posted February 2, 2021 Hey brian!, I really appreciate you pointing me in the right direction. I was able to accomplish what I needed within a hook. I've got a lot more to go, but now have a good idea how proceed. Thank you! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.