Jump to content

im getting empty values in smarty template


Jomart_123

Recommended Posts

im pulling data from DB to pass them to smarty clientareahome.tpl from a hook
 

<?php
use Illuminate\Database\Capsule\Manager as Capsule;

function hook_pullingCustomerData($vars){

   $customerID = $_SESSION['uid'];

   $hostingData = Capsule::table('tblhosting')
                       ->where('userid', $customerID)
                       ->get();
                       
   return array("customerHostingData" => $hostingData);

}
add_hook("ClientAreaPage", 1, "hook_pullingCustomerData");

on the template file i have this 

{$customerHostingData.domain}

im getting an empty space, instead of the domain name,  Any ideas???

Link to comment
Share on other sites

23 hours ago, Jomart_123 said:

im getting an empty space, instead of the domain name,  Any ideas???

it's because $customerHostingData will be an array and not a variable - so the usual display method would be a foreach loop in the template (you'll find many examples of how to do that already in the templates).

<?php
use Illuminate\Database\Capsule\Manager as Capsule;

function hook_pullingCustomerData($vars){

	$client = Menu::context('client');
	$hostingData = Capsule::table('tblhosting')
			->where('userid', $client->id)
			->get();
	$encodedata = json_encode($hostingData);
	$decodedata = json_decode($encodedata, true);

	return array("customerHostingData" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "hook_pullingCustomerData");

you could access the array values directly, e.g the first domain would be {$customerHostingData.0.domain}, but generally you would loop through the array.

also, adding {debug} to the end of the template, will generate a popup window of available variables and arrays - just remember to remove the code from the template, when you've finished.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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