Jump to content

Smarty var in array


yggdrasil

Recommended Posts

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 by yggdrasil
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated