Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Array Tree Variables

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
anythingpixel
Smarty n00b


Joined: 15 Feb 2016
Posts: 4

PostPosted: Mon Feb 15, 2016 4:35 pm    Post subject: Array Tree Variables Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Feb 15, 2016 5:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
anythingpixel
Smarty n00b


Joined: 15 Feb 2016
Posts: 4

PostPosted: Mon Feb 15, 2016 8:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
CrazyTemplate
Smarty Rookie


Joined: 12 Sep 2011
Posts: 31

PostPosted: Mon Feb 15, 2016 9:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
anythingpixel
Smarty n00b


Joined: 15 Feb 2016
Posts: 4

PostPosted: Mon Feb 15, 2016 10:17 pm    Post subject: Reply with quote

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 (Cool
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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Feb 15, 2016 11:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP