|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
anythingpixel Smarty n00b
Joined: 15 Feb 2016 Posts: 4
|
Posted: Mon Feb 15, 2016 4:35 pm Post subject: Array Tree Variables |
|
|
How do I write the syntax for variables I want to print on screen within an array tree. So for example, if I am looking at the debug and the tree looks like:
[code]Array
(
- [cart] => Array
(
- [3] => Array
(
[prod_id] => 8603
[cat] => h
[parent] => 0
+[all_cats] => Array
[sku] => SKU-NAME[/code]
How do I print the "SKU-NAME"
I've tried {$cart.sku} and it doesn't work. So I do I add in between the $cart and the sku?
Last edited by anythingpixel on Mon Feb 15, 2016 8:08 pm; edited 3 times in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Feb 15, 2016 5:39 pm Post subject: |
|
|
Learn to use BBcode and format your posts better so they can be properly understood.
Right now, I can't say, where's your sku is located in the structure, but it is definitely NOT in the 'cart'. |
|
Back to top |
|
anythingpixel Smarty n00b
Joined: 15 Feb 2016 Posts: 4
|
Posted: Mon Feb 15, 2016 8:04 pm Post subject: |
|
|
AnrDaemon wrote: | Learn to use BBcode and format your posts better so they can be properly understood.
Right now, I can't say, where's your sku is located in the structure, but it is definitely NOT in the 'cart'. |
Sorry, I'm a noobie on here. |
|
Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 31
|
Posted: Mon Feb 15, 2016 9:47 pm Post subject: |
|
|
It is not very clear what your array looks like, but I'll give it a try anyway:
$array['cart'][3]['sku']
But it may be wrong since you didn't post the entire thing. Try again but without any brackets. |
|
Back to top |
|
anythingpixel Smarty n00b
Joined: 15 Feb 2016 Posts: 4
|
Posted: Mon Feb 15, 2016 10:17 pm Post subject: |
|
|
CrazyTemplate wrote: | It is not very clear what your array looks like, but I'll give it a try anyway:
$array['cart'][3]['sku']
But it may be wrong since you didn't post the entire thing. Try again but without any brackets. |
Hi. Thanks for the response. I can't figure out how to post the code neatly in the forum text box to show the formatting. What I am trying to do is read a {debug} output from a site's page and write the syntax code to display a variable on the screen.
So for example, the small piece of the array i showed above is just part of the output the debug is showing me.
So on the left side it has {$cart}
On the right side it has:
Array (1)
4 => Array (75)
prod_id => "1044"
cat => "1464"
parent => "0"
all_cats => Array (
0 => "1464"
1 => "1594"
2 => "1633"
3 => "1751"
4 => "1972"
5 => "1981"
6 => "2020"
7 => "2049"
sku => "KE-DM0706"
qty => 1
ext_id => ""
cust_1 => false
SO, I am trying to have the sku print within pieces of code that's in a script like this:
"Quantity": "{$prod_id}",
"Id": "{$array['cart'][3]['sku']}
"ImageUrl": "{$cart.web}",
"Name": "{$valid.prod_name}",
So were it has "Id": " "
I want to put something that will print the id. I was trying {$cart.sku} based on the debug, but that didn't work. Seems like {$cart} has an array with all the variables listed in that debug, but I don't know how to get the array portion.
{$cart.array.sku}?? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Feb 15, 2016 11:16 pm Post subject: |
|
|
anythingpixel wrote: | So on the left side it has {$cart}
Code: | Array (1)
4 => Array (75)
prod_id => "1044"
cat => "1464"
parent => "0"
all_cats => Array (8)
0 => "1464"
1 => "1594"
2 => "1633"
3 => "1751"
4 => "1972"
5 => "1981"
6 => "2020"
7 => "2049"
sku => "KE-DM0706"
qty => 1
ext_id => ""
cust_1 => false |
|
http://php.net/arrays
You should REALLY learn language basics before trying to write your code.
Your $cart is an array with numeric index, you have to address it by that index or iterate over it to get further. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|