yggdrasil Posted August 11, 2020 Share Posted August 11, 2020 (edited) I finally decided to do some clean up on my templates by starting to remove PHP code from smarty templates. I know, I know, you are not supposed to use code on templates and put them in hooks, but I never did this because hooks tend to stop working on future updates as opposed to direct code on template files that always works and hooks tend to be slow in performance (and buggy). Either way, using the {php} in templates is wrong and it will probably be removed in future versions. I don't know how else to pass PHP code to templates except the bugged hook system, but if someone knows a better system I welcome a better approach. Since using PHP on pages is a must requirement in my case. Anyway, I'm now trying to get the smarty variables from the hook which like this: $clientsData = isset($vars['clientsdetails']) ? $vars['clientsdetails'] : null; This works fine for example to get the ID in PHP: $userId = $clientsData['firstname']; Do what ever you want and then pass it back to the template. Works great for variables that are not in an array like the clientdetails fields. But I'm having an issue to get template variables that are in categorized under an array. For example $contactdetails Origin: "Smarty object" Value Array (4) Registrant => Array (10) Full Name => "Company." Email => "email@email.com" Company Name => "Company Corp." Address 1 => "944 St." Does someone know how I would access the array Address 1? I can't just tap Address 1 directly since it's under the Registrant array which I need to specify somewhere. Edited August 11, 2020 by yggdrasil 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 11, 2020 Share Posted August 11, 2020 8 hours ago, yggdrasil said: Does someone know how I would access the array Address 1? directly using the code below if you're just wanting to retrieve it's value... $vars['contactdetails']['Registrant']['Address 1']; usually, i'd make contactdetails an array and then access the elements inside it as normal... $contactdetails = $vars['contactdetails']; $regadd1 = $contactdetails['Registrant']['Address 1']; but either method should work. 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted August 16, 2020 Author Share Posted August 16, 2020 On 8/11/2020 at 7:28 AM, brian! said: directly using the code below if you're just wanting to retrieve it's value... $vars['contactdetails']['Registrant']['Address 1']; usually, i'd make contactdetails an array and then access the elements inside it as normal... $contactdetails = $vars['contactdetails']; $regadd1 = $contactdetails['Registrant']['Address 1']; but either method should work. Thank you Brian! Worked on the first try. 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.